How with google text-to-speech (gTTS) I can save to the MP3 file 2 Variables with different languages? (Python)

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.

Upvotes: 0

Views: 1093

Answers (1)

YashasS
YashasS

Reputation: 21

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

os.system("from_file.mp3")

Upvotes: 2

Related Questions