コード例 #1
0
def generateAudio():
    try:
        os.system("rm *.mp3")
        os.system("rm static/output.mp3")
    except:
        pass
    allFiles = {"audio_files": []}
    print str(request.form)
    text = str(request.form).partition("'text', ")[2]
    if '"' in str(text)[:5]:
        text = text.partition('"')[2].partition(")]")[0][:-1]
    else:
        text = text.partition("'")[2].partition(")]")[0][:-1]

    print text
    for val in splitWords(text):
        allFiles['audio_files'].append(vocal.generateURL(str(val), 'en'))
    if len(allFiles['audio_files']) == 1:
        saveMP3(allFiles['audio_files'][0], "static/output.mp3")
    else:
        for i, val in enumerate(allFiles['audio_files']):
            saveMP3(val, "{}.mp3".format(str(i).zfill(2)))
        os.system("mp3wrap output.mp3 *.mp3")
        os.system("mv *MP3WRAP.mp3 static/output.mp3")
        os.system('ls')
    return allFiles
コード例 #2
0
def submitSpeech():
    start = time.time()
    tempDict = {}
    try:
        print request.data
    except:
        pass
    print request.form
    if 'to_language' in request.form:
        # To language is the language to convert to
        # ^ Agent language
        language = request.form['to_language']
        text = request.form['text']
    elif 'form-data; name="text"' in str(request.form):
        g = str(request.form).split("\n\n")
        text = g[1].partition("\n")[0]
        language = g[2].partition("\n")[0]
        print text
        print language
    else:
        tempDict['success'] = False
        tempDict['message'] = "Yo look to your left"
        end = time.time()
        tempDict['time_elapsed'] = (end - start)
        return jsonify(tempDict)
    tempDict = {}
    languageInfo = vocal.getLanguage(text)
    tempDict['language'] = languageInfo.lang
    tempDict['language_confidence'] = languageInfo.confidence
    tempDict['success'] = True
    tempDict['message'] = "Hello from the software engineering summit!"
    tempDict['original_text'] = text
    tempDict['new_text'] = vocal.translateText(text, language)
    tempDict['new_text_speech'] = vocal.generateURL(tempDict['new_text'],
                                                    language)
    tempDict['sentiment'] = float("{0:.2f}".format(
        analytics.getSentiment(text)))
    tempDict['keywords'] = analytics.getKeywords(tempDict['new_text'])
    tempDict['verbosity'] = float("{0:.2f}".format(
        float(len(' '.join(tempDict['keywords']).split(' '))) /
        float(len(text.split(" ")))))
    tempDict['word_count'] = len(text.split(" "))
    tempDict['new_word_count'] = len(tempDict['new_text'].split(" "))
    end = time.time()
    tempDict['time_elapsed'] = (end - start)
    return jsonify(tempDict)
コード例 #3
0
def generateComment():
    tempDict = {}
    text = random.choice(COMMENTS['complaints'])
    tempDict['text'] = text
    tempDict['sentiment'] = float("{0:.2f}".format(
        analytics.getSentiment(text)))
    tempDict['success'] = True
    tempDict['message'] = "Hello from the software engineering summit!"
    tempDict['new_text_speech'] = vocal.generateURL(
        re.sub(r'([^\s\w]|_)+', '', text), 'en')
    tempDict['sentiment'] = float("{0:.2f}".format(
        analytics.getSentiment(text)))
    tempDict['keywords'] = analytics.getKeywords(text)
    tempDict['verbosity'] = float("{0:.2f}".format(
        float(len(' '.join(tempDict['keywords']).split(' '))) /
        float(len(text.split(" ")))))
    tempDict['word_count'] = len(text.split(" "))
    return jsonify(tempDict)
コード例 #4
0
def partGenerateAudio(text, languageVal='en'):
    try:
        os.system("rm *.mp3")
        os.system("rm static/output.mp3")
    except:
        pass
    allFiles = {"audio_files": []}
    for val in splitWords(text):
        print re.sub(r'([^\s\w]|_)+', '', val)
        allFiles['audio_files'].append(vocal.generateURL(
            str(val), languageVal))
    if len(allFiles['audio_files']) == 1:
        saveMP3(allFiles['audio_files'][0], "static/output.mp3")
    else:
        for i, val in enumerate(allFiles['audio_files']):
            saveMP3(val, "{}.mp3".format(str(i).zfill(2)))
        os.system("mp3wrap output.mp3 *.mp3")
        os.system("mv *MP3WRAP.mp3 static/output.mp3")
        os.system('ls')
    return allFiles