Save to audio
GonESI opened this issue · 5 comments
Hi, I was wondering if there is any way to save the returned audio to any audio format.
Thanks in advance (the voice is superb).
Hi,
Currently there is no easy way to do this, but you can run google_speech
with -v debug
, copy the URL, download it, and save it as an MP3 file.
It would be really nice to be able to do this. I hacked this together to dump the audio files into /tmp/google_speech
:
https://github.com/alphapapa/GoogleSpeech/tree/dump-audio
I had first tried to pull them directly out of the cache database, but they are re-compressed, which means they aren't plain mp3 files. (This is strange, because they are already MP3 files, so compressing them with gzip or bzip2 doesn't gain anything.)
@alphapapa the code in the web_cache.py
is generic and I use it in several other projects, but in google_speech the compression is never used.
What is stored in the database is the raw MP3 file, which you can see for example on Linux with:
$ sqlite3 ~/.cache/google_speech/google_speech-cache.sqlite "SELECT data FROM sound_data LIMIT 1;" > /tmp/a.mp3
$ file /tmp/a.mp3
/tmp/a.mp3: MPEG ADTS, layer III, v2, 32 kbps, 16 kHz, Monaural
@desbma Oops, I didn't read the code closely enough, I just hacked something together. :) I had tried copying the data out of the database with a SQLite database editor, but I guess it couldn't handle binary data. Thanks for your help.
And BTW thanks for continuing to update this project. I used it yesterday for the first time in a while and it didn't work, but I upgraded it with pip and it worked again. Much appreciated!
I made a docker container to solve this problem for myself. It's a bit hacky, I'm basically using ffmpeg to record the google_speech
audio output.
Maybe it could be interesting for someone else: https://github.com/emazzotta/tts2audio