1

我有一个问题,当我在 python 中使用 SpeechRecognition 库时,当我想放入r.listen(source)while 循环时,我的代码会急剧变慢。

import speech_recognition as sr
import pyttsx3 as p
import random
from talk import *


r = sr.Recognizer()
engine = p.init()


    
with sr.Microphone() as source:
    while 0<1:
        text = r.listen(source)
        try:
            recognised_text = r.recognize_google(text)
            print(recognised_text)
            if (recognised_text =="hello" or recognised_text =="hi"):
                greeting()
        except sr.UnknownValueError:
            print("")
        except sr.RequestError as e:
            print("")
4

0 回答 0