0

我是一个初学者,我对语音识别和热门词不太了解。

到目前为止,我一直在使用 SpeechRecognition 模块,但它并不准确:

  1. 我必须等待程序访问我的麦克风
  2. 它甚至不准确我使用ambient_noise

这是我到目前为止所尝试的

    try:
        with sr.Microphone() as source:
            r.adjust_for_ambient_noise(source, duration=2)
            listening_audio = r.listen(source, phrase_time_limit=3)
            try:
                command = r.recognize_google(listening_audio, language='en-in')
                self.Command.emit(command)
            except sr.UnknownValueError:
                print('')
            except Exception as e:
                print('First error:', str(e))
    except Exception as e:
        print("Second error:", str(e))

我希望帮助我的程序按预期工作,或者如果有人可以给我额外的 Snowboy 网站。他们中的任何一个都会帮助我实现我的目标。

4

1 回答 1

0

尝试使用该pyttsx3模块speech_recognition

import speech_recognition as sr
import pyttsx3

engine = pyttsx3.init('sapi5')

voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)

rate = engine.getProperty('rate')
engine.setProperty('rate', rate-70)

volume = engine.getProperty('volume')
engine.setProperty('volume', 1)

i = 0
n = 0

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

while (i<1):
    r = sr.Recognizer()
    with sr.Microphone() as source:
        audio = r.adjust_for_ambient_noise(source)
        n=(n+1)
        print("Waiting For Voice Input...")
        audio = r.listen(source)
                                                   # interprete audio (Google Speech Recognition)
    try:
        s = (r.recognize_google(audio))
        message = (s.lower())
        print(message)
        
    except sr.UnknownValueError:
        print("Retry")
    except sr.RequestError as e:
        print("Could not request results$; {0}".format(e))
        try:
            speak("Sir Bad Signal")
        except:
            print("Sir Bad Signal")

这应该有效,并且应该比您的代码更好。试试看。

于 2021-01-06T11:47:12.647 回答