Skip to content

Commit

Permalink
Merge pull request newfies-dialer#48 from joshpatten/msspeak
Browse files Browse the repository at this point in the history
Feature: MSTranslator Text2Speech integration
  • Loading branch information
areski committed Oct 12, 2015
2 parents 0af69f7 + 6fc6258 commit 1105587
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 4 deletions.
10 changes: 8 additions & 2 deletions lua/libs/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ DBPASS = 'password'
DBPORT = 5432

--
-- Select the TTS engine, value : flite, acapela
-- Select the TTS engine, value : flite, acapela, mstranslator
--
TTS_ENGINE = 'flite'

Expand All @@ -19,9 +19,15 @@ TTS_ENGINE = 'flite'
ACCOUNT_LOGIN = 'EVAL_VAAS'
APPLICATION_LOGIN = 'EVAL_YYYYYYY'
APPLICATION_PASSWORD = 'XXXXXXXX'

SERVICE_URL = 'http://vaas.acapela-group.com/Services/Synthesizer'
QUALITY = '22k' -- 22k, 8k, 8ka, 8kmu
ACAPELA_GENDER = 'W'
ACAPELA_INTONATION = 'NORMAL'
ACAPELA_LANG = 'EN'

--
-- Microsoft Translator TTS Settings
--
CLIENT_ID = 'XXXXXXXXXXXX'
CLIENT_SECRET = 'YYYYYYYYYYYYYY'
MSTRANSLATOR_LANG = 'EN'
11 changes: 11 additions & 0 deletions lua/libs/texttospeech.lua
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,16 @@ function tts(text, tts_dir)
output_file = tts_acapela:run()
end

elseif TTS_ENGINE == 'mstranslator' then
-- Microsoft Translator
MSTranslator = require "mstranslator"
tts_mstranslator = MSTranslator:new{
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
DIRECTORY=tts_dir}
tts_mstranslator:set_cache(true)
tts_mstranslator:prepare(text, MSTRANSLATOR_LANG)
output_file = tts_mstranslator:run()
end
return output_file
end
8 changes: 6 additions & 2 deletions newfies/newfies_dialer/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,17 +534,21 @@

# TEXT-TO-SPEECH
# ==============
TTS_ENGINE = 'FLITE' # FLITE, CEPSTRAL, ACAPELA
TTS_ENGINE = 'FLITE' # FLITE, CEPSTRAL, ACAPELA, MSTRANSLATOR

# ACAPELA SPECIFIC SETTINGS
ACCOUNT_LOGIN = 'EVAL_XXXX'
APPLICATION_LOGIN = 'EVAL_XXXXXXX'
APPLICATION_PASSWORD = 'XXXXXXXX'

SERVICE_URL = 'http://vaas.acapela-group.com/Services/Synthesizer'
QUALITY = '22k' # 22k, 8k, 8ka, 8kmu
ACAPELA_GENDER = 'W'
ACAPELA_INTONATION = 'NORMAL'

# MSTRANSLATOR SPECIFIC SETTINGS
CLIENT_ID = 'XXXXXXXXXXXX'
CLIENT_SECRET = 'YYYYYYYYYYYYYY'

# DEBUG DIALER
# ============
DIALERDEBUG = False
Expand Down
16 changes: 16 additions & 0 deletions newfies/survey/function_def.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@
#
from django.conf import settings

def getaudio_mstranslator(text, tts_language='en'):
"""
Run Microsoft Speak Text2Speech and return audio url
"""
import msspeak
DIRECTORY = settings.MEDIA_ROOT + '/tts/'
if not tts_language:
tts_language = 'en'
tts_msspeak = msspeak.MSSpeak(
settings.CLIENT_ID,
settings.CLIENT_SECRET,
DIRECTORY)
output_filename = tts_msspeak.speak(
text, tts_language)
audiofile = 'tts/' + output_filename
return audiofile

def getaudio_acapela(text, tts_language='en'):
"""
Expand Down
4 changes: 4 additions & 0 deletions newfies/survey/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
SEALED_SURVEY_COLUMN_NAME
from survey.models import post_save_add_script
from survey.function_def import getaudio_acapela
from survey.function_def import getaudio_mstranslator
from django_lets_go.common_functions import striplist, ceil_strdate, getvar, unset_session_var,\
get_pagination_vars
from mod_utils.helper import Export_choice
Expand Down Expand Up @@ -512,6 +513,9 @@ def section_script_play(request, id):
if settings.TTS_ENGINE == 'ACAPELA':
# Acapela
audio_file_path = settings.MEDIA_ROOT + '/' + getaudio_acapela(script_text, 'US')
elif settings.TTS_ENGINE == 'MSTRANSLATOR':
# Microsoft Translator
audio_file_path = settings.MEDIA_ROOT + '/' + getaudio_mstranslator(script_text, 'en')
else:
# Flite
script_hexdigest = hashlib.md5(script_text).hexdigest()
Expand Down

0 comments on commit 1105587

Please sign in to comment.