def textToSpeech(text): wdc = WDCService('TS') text_to_speech = TextToSpeech(username=wdc.service.user, password=wdc.service.password) #print text_to_speech.voices() module_dir = os.path.dirname(__file__) filename = 'tts.wav' file_path = os.path.join(module_dir, '../static/', filename) with open(file_path, 'wb+') as audio_file: audio_file.write(text_to_speech.synthesize(text))
def text_speech(filename, text, locale="ja"): """ テキストデータを音声再生する @param text 音声再生するテキストデータ @param locale テキストのロケール @return なし """ from watson_developer_cloud import TextToSpeechV1 from os.path import join, dirname try: # IBM Cloud param inifile = configparser.ConfigParser() inifile.read('./config.ini', 'UTF-8') usr = inifile.get('text to speech', 'usr') pwd = inifile.get('text to speech', 'pwd') if locale == "ja": voice = "ja-JP_EmiVoice" else: voice = "en-US_AllisonVoice" text_to_speech = TextToSpeechV1(username=usr, password=pwd) with open(join(dirname(__file__), filename), 'wb') as audio_file: mp3data = text_to_speech.synthesize( text, accept='audio/mp3', voice=voice).get_result().content audio_file.write(mp3data) except Exception as e: traceback.print_exc() sys.exit()
def watson_cloud_tts(text, output_path, username, password): voice_list = [ 'en-US_AllisonVoice', 'en-US_LisaVoice', 'en-US_MichaelVoice', 'en-GB_KateVoice' ] text_to_speech = TextToSpeechV1( url='https://stream.watsonplatform.net/text-to-speech/api', username=username, password=password) # Text to speech api request for voice in voice_list: # Generate random voice characteristics random_rate = 'default' random_volume = 'default' random_pitch = 'default' for i in range(10): ssml = '<prosody rate="{0}" volume="{1}" pitch="{2}"> {3} </prosody>'.format(random_rate, \ random_volume, random_pitch, text) response = text_to_speech.synthesize(ssml, accept='audio/wav', voice=voice) file_name = 'watson_{0}{1}{2}{3}.wav'.format( voice, random_rate, random_volume, random_pitch) with open(output_path + '/' + file_name, 'wb') as f: f.write(response.content) random_rate = str(randint(-15, 15)) + '%' random_volume = str(randint(75, 100)) random_pitch = str(randint(-10, 10)) + 'Hz' print('audios in voice ' + voice + ' are created')
def __init__(self): self.url = "https://stream.watsonplatform.net/text-to-speech/api" self.username = "******" self.password = "******" self.text_to_speech = TextToSpeechV1( username = self.username, password = self.password)
def searchFood(term, limit=5, sort=2, radius_filter=8000): #sort = 2 is for highested rated params = { 'term': term, 'limit': limit, 'sort': sort, 'radius_filter': radius_filter, 'lang': 'fr' } result = client.search('Pittsburgh', **params) businesses = result.businesses names = "" for i in range(0, limit): if i == limit - 1: names += "and " + businesses[i].name else: names += businesses[i].name + ", " text_to_speech = TextToSpeechV1( username='******', password='******', x_watson_learning_opt_out=True) # Optional flag with open(join(dirname(__file__), 'resources/recommendations.wav'), 'wb') as audio_file: audio_file.write( text_to_speech.synthesize('Some good' + term + 'places are, ' + names, accept='audio/wav', voice="en-US_AllisonVoice")) audio = AudioFile('resources/recommendations.wav') audio.play() audio.close()
def __init__(self, username, password): print("Initializing TextToSpeech ...") self.user = username self.passwd = password self.tts = TextToSpeechV1( username=self.user, password=self.passwd, x_watson_learning_opt_out=True)
def main(): weather = Weather() text_to_speech = TextToSpeechV1( username='******', password='******', x_watson_learning_opt_out=True) # Optional flag def sound(text): with open('output.wav', 'wb') as audio_file: audio_file.write( text_to_speech.synthesize(text, accept='audio/wav', voice="en-US_AllisonVoice")) os.system('play output.wav') audio_file.close() # welcome text text = 'Hi! Are you ready for tree hacks? I will monitor your productivity by tracking your tab history!' sound(text) location = weather.lookup_by_location('san jose') condition = location.condition() print(condition.text()) text = 'Let me check the weather for you. Here you go! The weather of today in San Jose is ' + condition.temp( ) + 'degrees, ' + condition.text() sound(text) text = 'Seems like a less favorable day to go hang-out. Well you should probably hack hack hack.' sound(text)
def tts(nombre,vol=0): archivo = "" for cont,a in enumerate(nombre): if cont > 240: break if a == "ñ" or a == "Ñ": archivo += "n" elif a.isalnum(): archivo += a else: if a == "?": archivo += "-" if a == ',' or a == '.': archivo += a #archivo = nombre.replace(" ","").replace("?","-").replace(":","").replace("|","").replace("<","").replace(">","").replace("\\","").replace("/","").replace("*","").replace('"',"") if equipo == "posix": archivo = os.getcwd()+"/tts/audios/"+archivo+".wav" else : archivo = "audios/"+archivo+".wav" if isfile(archivo): reproducir(archivo,vol) print(nombre) else: from watson_developer_cloud import TextToSpeechV1 text_to_speech = TextToSpeechV1( username='******', password='******') with open(join(dirname(__file__), archivo),'wb') as audio_file: audio_file.write(text_to_speech.synthesize(nombre, accept='audio/wav',voice="es-ES_EnriqueVoice").get_result().content) audio_file.close() reproducir(archivo,vol) print(nombre)
def robotVoice(): text_to_speech = TextToSpeechV1( iam_apikey= watsonApiKey['iam_apikey'], url=watsonApiKey['url'] ) def sentencesToVoice(sentence,filename): output = './content/{}-audio.wav'.format(filename) try: with open(output, 'wb') as audio_file: audio_file.write( text_to_speech.synthesize( sentence, voice='en-US_AllisonVoice', accept='audio/wav' ).get_result().content) return True except: return False def fetchVoicesOfAllSentences(content): print('> Fetching voices of all sentences...') for i,item in enumerate(content['sentences']): content['sentences'][i]['audio'] = sentencesToVoice(content['sentences'][i]['text'],i) print('> Fetch voices of all sentences concluded') return content content = loadContent() fetchVoicesOfAllSentences(content) saveContent(content)
class Transcribe: """This class encapsulates the IBM watson TextToSpeech API. this class is imported and the method output is called where ever text to speech transcription is needed. The method output saves an audio file 'output_en-US_LisaVoice.wav' as its output. the systems omxplayer is then used to play the audio file output. the output is not static and changes for each successful speech to text transcription""" # username = "******" older password # password = "******" older password # username = "******" old username # password = "******" old password username = "******" password = "******" voice = "en-US_LisaVoice" # voice = "en-GB_KateVoice" # voice = "en-US_AllisonVoice" text_to_speech = TextToSpeechV1(username=username, password=password) base_dir = os.getcwd() base_dir2 = "/home/pi/Desktop/home_ai_annah" audio_commands = os.path.join(base_dir2, "audio_commands") fn = 'output_' + voice + '.wav' file_output = os.path.join(audio_commands, fn) def output(self, text): """Method takes text file as input and returns an audio file containing the voice transcription of the text it then calls the systems music player 'omxplayer' to play the transcribed audio corresponding to the text""" with open(self.file_output, 'wb') as audio_file: audio_file.write(self.text_to_speech.synthesize(text, voice=self.voice)) os.system("omxplayer '{}'".format(self.file_output))
def text_to_speech(input_text, model, filename): tts = TextToSpeechV1(iam_apikey=keys.text_to_speech_key) #open a file for writing. send text to synthesize and result to file with open(filename, 'wb') as output_speech: output_speech.write(tts.synthesize(text=input_text, accept='audio/wav', voice=model).get_result().content)
def __init__(self, username, password): self.user = username self.pas = password self.text_to_speech = TextToSpeechV1(username=username, password=password, x_watson_learning_opt_out=True) self.fileLocation = "/home/pi/tj-python-master/resources/"
def __init__(self): self.text_to_speech = TextToSpeechV1( #iam_apikey='nBVvz1-p4Q3F0rF_L8c0UmCfirPNfIKaVO32prppKCzR', #iam_apikey='UvuwivzdQoLY7xOEzLVvPKAmsK7-iprq2u1T1Q2B81mW', iam_apikey='4L-eAWw0E68Ym8cv9xd_PLVsvi6GIjvXWNseM2qjW-kb', url='https://stream.watsonplatform.net/text-to-speech/api' ) self.localDir = os.path.dirname(__file__) self.absDir = os.path.join(os.getcwd(), self.localDir) self.pitchLookup = { "F": -100, "F#": -80, "G": -60, "G#": -39, "A": -19, "A#": 3, "B": 23, "C": 44, "C#": 66, "D": 90 } for i in self.pitchLookup: self.pitchLookup[i] += 9 self.fileNum = 1
def to_speak(text_to_speak, voice_to_use, file_name): tts = TextToSpeechV1(iam_apikey=keys.text_to_speech_key) with open(file_name, 'wb') as audio_file: audio_file.write(tts.synthesize(text_to_speak, accept='audio/wav', voice=voice_to_use).get_result().content) sound = pydub.AudioSegment.from_wav(file_name) pydub.playback.play(sound)
def __init__(self): self.STT = SpeechToText( username='******', password='******') self.TTS = TextToSpeech( username='******', password='******')
def text_speech(text): u = os.envion.get("TS_USERNAME") p = os.envion.get("TS_PASSWORD") text_to_speech = TextToSpeechV1(username=u,password=p,x_watson_learning_opt_out=True) # Optional flag filepath = os.join(os.dirname(os.dirname(__file__)), 'static/audio/output.wav') with open(filepath,'wb') as audio_file: audio_file.write(text_to_speech.synthesize(text, accept='audio/wav',voice="en-US_AllisonVoice")) return filepath
def text_speech(text): u = '44a4623d-a370-483a-81ea-9c19d4d75cc7' p = 'BbX6WUkbXbGT' text_to_speech = TextToSpeechV1(username=u, password=p, x_watson_learning_opt_out=True) # Optional flag filepath = os.path.join(os.path.dirname(__file__), 'static/audio/output.wav') with open(filepath,'wb') as audio_file: audio_file.write(text_to_speech.synthesize(text, accept='audio/wav', voice='fr-FR_ReneeVoice')) return filepath
def __init__(self, username, password): self.user = username self.pas = password self.text_to_speech = TextToSpeechV1( username=username, password=password, x_watson_learning_opt_out=True) self.fileLocation = "/home/pi/SeniorProjectBioloid/resources/"
def __init__(self): print("My init is starting") self.text_to_speech = TextToSpeechV1( iam_apikey='nBVvz1-p4Q3F0rF_L8c0UmCfirPNfIKaVO32prppKCzR', url='https://stream.watsonplatform.net/text-to-speech/api') self.localDir = os.path.dirname(__file__) self.absDir = os.path.join(os.getcwd(), self.localDir) print("My init is ending")
def text_to_speech_fun(): text_to_speech = TextToSpeechV1( username='******', password='******', x_watson_learning_opt_out=True) return text_to_speech
def speak(self, filename, text, rate_change="+0%", f0mean_change="+0%"): tts = TextToSpeechV1(username='******', password='******') ssml_text = '<prosody rate="%s" pitch="%s"> %s </prosody>' % (rate_change, f0mean_change, text) with open(filename, 'wb') as audio_file: audio_file.write(tts.synthesize(ssml_text, accept='audio/wav', voice="es-US_SofiaVoice")) audio_file.close()
def __init__(self): print("Starting text to speech") self.voice = NAO_VOICE self.nao_tts = ALProxy("ALTextToSpeech", "localhost", 9559) self.watson_tts = TextToSpeechV1( username="******", password="******")
def request(fname, str): text_to_speech = TextToSpeechV1( iam_apikey=ServerKeys.WATSON_KEY, url='https://gateway-wdc.watsonplatform.net/text-to-speech/api') with open(fname, 'wb') as audio_file: audio_file.write( text_to_speech.synthesize( str, 'audio/wav', 'en-US_AllisonVoice').get_result().content)
def watson_text_to_speach_service(self, text): texttospeach = TextToSpeechV1(username=self.username, password=self.password) response = texttospeach.synthesize(text=text, accept=self.accept, voice=self.voice) self.response = response
def __init__(self, username, password): self.user = username self.pas = password self.text_to_speech = TextToSpeechV1( username=username, password=password, url='https://stream.watsonplatform.net/text-to-speech/api') #x_watson_learning_opt_out=True) self.fileLocation = "/home/pi/SeniorProjectBioloid/resources/"
def __init__(self,debug_mode=False): self.debug_mode=debug_mode f = open("key.txt", "r") f1 = f.read().splitlines() f.close() self.text_to_speech = TextToSpeechV1( iam_apikey=f[14], url=f[15] )
def tts(text, lang): #language mapping based on ISO 639-1 #see instructions on how to add a new language/voice languages = { "es": "es-ES_EnriqueVoice", #default "en": "en-US_MichaelVoice", "de": "de-DE_BirgitVoice", "fr": "fr-FR_ReneeVoice", "it": "it-IT_FrancescaVoice", "ja": "ja-JP_EmiVoice", "pt": "pt-BR_IsabelaVoice", "default": "es-ES_EnriqueVoice" } #Text to Speech service credentials #flag is used to break the loop and exit the program username = '******' password = '******' flag = True #parse input arguments if not utils.validateInputArgs(sys.argv[1]): #CHANGE MADE HERE: sys.argv --> sys.argv[1] print( "Invalid arguments. Expected: \npython2 text2speech.py \"language(optional)\"" ) sys.exit() #get voice and lanugage from 2nd parameter argument voice = languages[lang] #loop to iterate input while flag: #validate input and proceed if utils.validateInput(text): parsedText = text.strip() text_to_speech = TextToSpeechV1(username=username, password=password) # Optional flagFalse #convert text input and save temp audio file with open('output.mp3', 'w+b') as audio_file: audio_file.write( text_to_speech.synthesize(parsedText, accept='audio/mp3', voice=voice).content) print('Conversion completed. Playing audio..') playsound('output.mp3') flag = 0 else: print( 'Input cannot be empty. Please enter a phrase or sentence for conversion' ) break
def text_to_speech(text_to_speak, voice_to_use, file_name): """Use Watson Text to Speech to convert text to specified voice and save to a WAV file.""" # create Text to Speech client tts = TextToSpeechV1(iam_apikey=keys.text_to_speech_key) # open file and write the synthesized audio content into the file with open(file_name, 'wb') as audio_file: audio_file.write(tts.synthesize(text_to_speak, accept='audio/wav', voice=voice_to_use).get_result().content)
def main(): dotenv_path = join(dirname(__file__), '.env') load_dotenv(dotenv_path) tts = TextToSpeechV1(username=os.environ.get("TTS_USERNAME"), password=os.environ.get("TTS_PASSWORD"), x_watson_learning_opt_out=True) # Optional flag text = "Watson loves galvanize and Seattle" convert_to_audio(tts, text)
def getSpeechFromText(text): text_to_speech = TextToSpeechV1(iam_apikey=api_key, url=url) text_to_speech.set_detailed_response(True) text_synthezation_results = text_to_speech.synthesize( text=text, accept='audio/wav', voice='en-US_MichaelVoice' ).get_result().content return text_synthezation_results
def voiceResponse(text): text_out = text if text_out: text_to_speech = TextToSpeechV1(url="https://stream-fra.watsonplatform.net/text-to-speech/api", username='******', password='******', x_watson_learning_opt_out=True) # Optional flag with open('output.wav', 'wb') as audio_file: audio_file.write(text_to_speech.synthesize(text_out, accept='audio/wav', voice="en-US_AllisonVoice")) os.system("play output.wav")
import json from os.path import join, dirname from watson_developer_cloud import TextToSpeechV1 as TextToSpeech text_to_speech = TextToSpeech(username='******', password='******') print(json.dumps(text_to_speech.voices(), indent=2)) with open(join(dirname(__file__), '../resources/output.wav'), 'wb') as audio_file: audio_file.write(text_to_speech.synthesize('Hello world!'))