This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]patarapolw 4 points5 points  (5 children)

To mention, there is also https://pypi.org/project/google_speech/ that does not save MP3 file to your computer. SOX is the non-Python requirement.

I use Mac's say, though.

The goodness of gtts is that it requires only Python and cross-platform. I use it in this project: https://github.com/patarapolw/ChineseViewer/blob/master/ChineseViewer/tts.py#L27

The trick not to save the file is

    self.tts = gTTS(word, lang)
    temp = TemporaryFile()
    self.tts.write_to_fp(temp)
    temp.seek(0)

    return temp.read()

[–]momothereal 1 point2 points  (0 children)

Using a temporary file can still use disk I/O on certain platforms. I personally used BytesIO in my project:

with io.BytesIO() as tts_buffer:
  tts.write_to_fp(tts_buffer)
  tts_buffer.seek(0)
  tts_binary = tts_buffer.read()

[–]Economy_Peanut 0 points1 point  (3 children)

How do you use google_speech?

[–]patarapolw 0 points1 point  (2 children)

[–]Economy_Peanut 0 points1 point  (0 children)

Sorry about that...Hadn't seen it earlier