问题描述
我正在使用Google文字进行语音转换,成为树莓派聊天机器人。这是我的代码:
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,slow=slow_audio_speed)
audio_created2.save(filename2)
os.system(f'start {filename2}')
def reading_from_string3():
audio_created3 = gTTS(text=text_to_read3,slow=slow_audio_speed)
audio_created3.save(filename3)
os.system(f'start {filename3}')
def reading_from_string4():
audio_created4 = gTTS(text=text_to_read4,slow=slow_audio_speed)
audio_created4.save(filename4)
os.system(f'start {filename4}')
def reading_from_string5():
audio_created5 = gTTS(text=text_to_read5,slow=slow_audio_speed)
audio_created5.save(filename5)
os.system(f'start {filename5}')
def reading_from_string6():
audio_created6 = gTTS(text=text_to_read6,slow=slow_audio_speed)
audio_created6.save(filename6)
os.system(f'start {filename6}')
def reading_from_string11():
audio_created11 = gTTS(text=text_to_read11,slow=slow_audio_speed)
audio_created11.save(filename11)
os.system(f'start {filename11}')
def reading_from_string12():
audio_created12 = gTTS(text=text_to_read12,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。
以下是打开的文件在其中读写:
这是代码产生的错误(它说我输入的内容都不是什么,当它说sh时:1:开始:使用我使用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
您知道哪里出了问题以及如何解决吗?
谢谢。
解决方法
该错误是由于start
不是您要在其上运行脚本的操作系统上的命令所致。 start
仅在Windows的cmd.exe
下可用。
在raspbian you can use omxplayer --no-keys <filename>
instead上。