Python 没有说什么就无法启动语音识别

Python Speech Recognition not starting without saying anything

我正在使用 Python 的语音识别、pyaudio 和 Python 文本到语音模块创建一个 Python 个人助理,所以我想要的是在启动程序后我想让它说些什么并对其进行相同的编码,但是当我 运行 程序时,它首先开始收听,直到除非我向它提供任何随机词,否则它不会继续前进。这是主要功能的代码。

import speech_recognition as sr 
import random
import functions.Response as speech
import functions.custom_input
import functions.device_stats
import num2words
import sys,os
import functions.check_user
from functions.Response import say,listen

def check():
    say("Starting Program")
    say("Initializing modules")
    say("Modules Intialized")
    say("Performing System Checks")
    say("Sytem Checks Done")
    say("Starting happy protocol")
    
check()


有什么想法吗?怎么办?

您的程序缺少很多信息。这不是问题,因为我去过你所在的地方。您缺少一些代码行。这里没有导入诸如 say 函数或响应之类的东西,而是一个有效且更简单的替代方法。

import pyttsx3
import speech_recognition as sr


engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)

def say(audio):
    engine.say(audio)
    engine.runAndWait()

def check():
    say("Starting Program")
    say("Initializing modules")
    say("Modules Intialized")
    say("Performing System Checks")
    say("Sytem Checks Done")
    say("Starting happy protocol")

check()

您以后基本上可以为您的虚拟助手添加命令...