spacepaste

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