python - 如何使用语音 gtts 进行用户输入
问题描述
我正在创建一个带有语音输入的简单比萨应用程序。在创建这篇文章之前,我搜索了很多,但没有发现任何有用的东西。
小提琴没有正确运行代码,所以不要在那里运行它。
问题:
当我尝试在“输入”中使用“命令”时(例如
count = 0
def talkToMe(audio):
global count
print(audio)
text_to_speech = gTTS(text=audio, lang='en-us')
text_to_speech.save(f'speech{count%2}.mp3')
mixer.init()
mixer.music.load(f'speech{count%2}.mp3')
mixer.music.play()
count += 1
def myCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print('Ready...')
r.pause_threshold = 1
r.adjust_for_ambient_noise(source, duration=1)
audio = r.listen(source)
try:
command = r.recognize_google(audio).lower()
print('You said: ' + command + '\n')
#loop back to continue to listen for commands if unrecognizable speech is received
except sr.UnknownValueError:
print('Your last command couldn\'t be heard')
command = myCommand();
return command
def assistant(command):
def pick_or_deli():
global delivery
global customer_name
global customer_telephone
delivery = input("pickup - pick up / delivery - delivery:" + command)
delivery = delivery.upper()
if delivery == "DELIVERY":
while running == True:
..............................
我只是得到:
不要注意小写的“交付”。即使我改变这一行:
if delivery == "DELIVERY":
对此:
if delivery == "delivery":
它不起作用。即使我按Enter。系统不会将其识别为输入。
任何关于此的解决方案/建议都会很棒。
解决方案
推荐阅读
- php - 当我运行控制 exe 时,Xampp 带来了 apache 和 mysql
- r - 如何将函数的打印输出存储为R中的向量?
- swift - 当您不知道使用什么值进行初始化时进行 Swift 初始化
- c# - 配置 Visual Studio 自动完成以列出命名空间之外的类?
- python - 为特定用户保存 .docx 文件 django
- python - 在 C++ 中,为什么某些参数需要 &?
- python - numpy arange 函数构建数组大小错误
- f# - 如何在 F# 中制作 uint32?
- ruby - Bundler 找不到 gem "bundle" 的兼容版本,但 gem 列表没有它说安装的版本
- c# - 'nvarchar 值 '267915267915' 的转换溢出了一个 int 列。