Replies: 2 comments 3 replies
-
Since I have a very long list of words to record, I had to improve performance to the detriment of beauty... I hope someone finds this helpful. from gtts import gTTS
import pandas as pd
# --------------------------------
## Create binary code for a short silence
# Ugly trick: utter a character that gTTS doesn't pronounce, thus resulting in a silence
# This is better than doing "pause.write_to_fp(f)" (it's too slow)
pause = gTTS("¤", lang='fr')
# Write the pause in a file
with open('test.mp3', 'wb') as f:
pause.write_to_fp(f)
# Save the binary corresponding to a short pause
with open('test.mp3', 'rb') as f:
pause_binary = f.read()
# --------------------------------
# Load words from external file
df = pd.read_csv('liste_vocab.tsv',sep="\t",names=['fr','ja'])
# --------------------------------
# Utter and create MP3
with open('french_japanese.mp3', 'wb') as f:
for i, w in enumerate(df.values):
gTTS(w[0], lang='fr').write_to_fp(f)#.save(f'fr_{i}.mp3')
# apply 5 short pauses
f.write(pause_binary*5)
gTTS(w[1], lang='ja').write_to_fp(f)#.save(f'ja_{i}.mp3')
f.write(pause_binary*6) |
Beta Was this translation helpful? Give feedback.
3 replies
-
I ran into this problem and found another approach - generate a set of silent audio frames of the desired length. there you can get the code - https://github.com/splash58/silence |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Is there any way to add pauses between sounds when writing them to "fp"?..
Here is my ugly trick until then:
This is very slow.
Beta Was this translation helpful? Give feedback.
All reactions