繁体   English   中英

如何使用 google text-to-speech (gTTS) 保存到 MP3 文件 2 不同语言的变量? (蟒蛇)

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

如何使用 google text-to-speech 我可以保存到 MP3 文件 2 不同语言的变量? 请帮帮我。 Everywhere 仅针对 1 种语言编写。 这是我的代码:

 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")

文件内容:

 English Русский tell говорить fly летать sit сидеть act действовать
作为解决方案:我可以使用 gTTS 循环每个单词并添加到 mp3 文件中,但是如何在不删除过去数据的情况下在 mp3 中添加数据? 我想创建一个音频词典。

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

os.system("from_file.mp3")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM