我正在使用谷歌文本到语音制作一个树莓派聊天机器人。这是我的代码:
import os
from gtts import gTTS
import time
text_to_read = "Hello my name is Alex. What's your name? "
language = 'en'
slow_audio_speed = False
filename = '1.mp3'
filename2 = '2.mp3'
filename3 = '3.mp3'
filename4 = '4.mp3'
filename5 = '5.mp3'
filename6 = '6.mp3'
filename7 = '7.mp3'
filename8 = '8.mp3'
filename9 = '9.mp3'
filename10 = '10.mp3'
filename11 = '11.mp3'
filename12 = '12.mp3'
def reading_from_string():
audio_created = gTTS(text=text_to_read, lang=language,
slow=slow_audio_speed)
audio_created.save(filename)
os.system(f'start {filename}')
def reading_from_string2():
audio_created2 = gTTS(text=text_to_read2, lang=language,
slow=slow_audio_speed)
audio_created2.save(filename2)
os.system(f'start {filename2}')
def reading_from_string3():
audio_created3 = gTTS(text=text_to_read3, lang=language,
slow=slow_audio_speed)
audio_created3.save(filename3)
os.system(f'start {filename3}')
def reading_from_string4():
audio_created4 = gTTS(text=text_to_read4, lang=language,
slow=slow_audio_speed)
audio_created4.save(filename4)
os.system(f'start {filename4}')
def reading_from_string5():
audio_created5 = gTTS(text=text_to_read5, lang=language,
slow=slow_audio_speed)
audio_created5.save(filename5)
os.system(f'start {filename5}')
def reading_from_string6():
audio_created6 = gTTS(text=text_to_read6, lang=language,
slow=slow_audio_speed)
audio_created6.save(filename6)
os.system(f'start {filename6}')
def reading_from_string11():
audio_created11 = gTTS(text=text_to_read11, lang=language,
slow=slow_audio_speed)
audio_created11.save(filename11)
os.system(f'start {filename11}')
def reading_from_string12():
audio_created12 = gTTS(text=text_to_read12, lang=language,
slow=slow_audio_speed)
audio_created12.save(filename12)
os.system(f'start {filename12}')
f=open('name.txt','r+')
x=f.read()
f.close()
answer = input (reading_from_string())
if answer == x :
text_to_read11 = "Hello again"
reading_from_string11()
f=open('name.txt','r')
g=f.read()
text_to_read12 = g
time.sleep(0.5)
reading_from_string12()
f.close()
else:
name=answer
f=open('name.txt', 'w')
f.write(name)
f.close()
text_to_read2 = 'Hello'
reading_from_string2()
text_to_read3 = (name)
time.sleep(0.5)
reading_from_string3()
text_to_read4= 'What do you like'
text_to_read6 = input (reading_from_string4())
y=open('likes.txt','w')
x=text_to_read6
y.write(x)
y.close()
text_to_read5 = 'storing memory'
reading_from_string5()
time.sleep(1)
reading_from_string6()
顺便说一句,它直接从 text_to_read6 到 text_to_read11 因为我删除了不必要的代码块。
以下是它打开读取和写入的文件:
这是代码产生的错误(在它说 none 是我输入的地方,当它说 sh: 1: start: not found 是它应该使用我使用 pip3 install gTTS 安装的 gTTS 模块说话的地方)
sh: 1: start: not found
Nonearthur
sh: 1: start: not found
sh: 1: start: not found
sh: 1: start: not found
Nonephysics maths and piano
sh: 1: start: not found
sh: 1: start: not found
你知道什么是错的,我该如何解决?
谢谢。