def generate_tts(text="This is default debug text. Pass a parameter to override."): """ :param text: text to be turned into tts ;var tts: tts data retrieved from translate.google.com/translate data seems to be 24kHz. converted to wav, the audio was very sped up. adjusting the freq to 44100 makes it sound normal ;var readwav: converted mp3 wav data for turning into """ tts = gTTS(text, lang='en') tts.save("temp.mp3") if os.path.isfile('temp.wav'): os.remove('temp.wav') ff = ffmpy.FFmpeg( inputs={'temp.mp3': None}, outputs={'temp.wav': ['-ar', '44100', '-ac', '1', '-acodec', 'dts', '-strict', '-2', '-f', 'wav']} ) ff.run() readwav = read("temp.wav") data = numpy.array(readwav.data, dtype=float) sounddevice.play(data)