0

How with google text-to-speech I can save to the MP3 file 2 Variables with different languages? Please help me. Everywhere is written only for 1 language. This is my code:

from gtts import gTTS
import os
import pickle
import pandas as pd

frame = pd.read_csv('file.csv', header=0, sep = '\t', encoding='cp1251')
print(frame)

text1 = list()
text2 = list()

for a, b in zip(frame['English'], frame['Русский']):
    text1.append(a)
    text2.append(b)

print(text1,
      text2)

text1 = str(text1)
text2 = str(text2)

tts1 = gTTS(text=text1, lang='en')
tts2 = gTTS(text=text2, lang='ru')


# tts2.save("from_file.mp3") it work just for one Variable!



with open('from_file.mp3', 'wb') as pickle_file:
    pickle.dump([tts1, tts2], pickle_file) 
# with pickle it doesn't work!

os.system("from_file.mp3")

file content:

English   Русский

tell   говорить
fly   летать
sit   сидеть
act   действовать
As a solution: I can loop every word with gTTS and add in mp3 file, but how can I add data in mp3 without delete past data ?? I want to create an audio dictionary.
  • You create individual files first, then you can combine files with ffmpeg https://stackoverflow.com/questions/4581417/combining-multiple-audio-files-in-python-with-delay – Nikolay Shmyrev Jan 25 '18 at 00:45

1 Answers1

2
with open('from_file.mp3', 'wb') as ff:
    tts1.write_to_fp(ff)
    tts2.write_to_fp(ff)  

os.system("from_file.mp3")
Fabich
  • 2,768
  • 3
  • 30
  • 44
YashasS
  • 21
  • 2