簡體   English   中英

我在 python 上做了一個虛擬助手,我不知道為什么語音識別不聽並打印我所說的

[英]Im making a virtual Assitant on python and i dont know why speech recognition doesnt listening and prints the what i have said

因此,正如我所說,我正在使用 Python 制作虛擬助手,而語音識別不聽我的,它不打印我所說的內容。 下面是代碼:

import speech_recognition as sr

def get_audio():
    print("listening...")
    r = sr.Recognizer()
    with sr.Microphone() as source:
        audio = r.listen(source)
        said = ""

        try:
            said = r.recognize_google(audio)
            print(said)
        except Exception as e:
            print("Exception: " + str(e))
        
    return said


get_audio()

在我以 python 運行和調試代碼后,它只說我在聽我在麥克風上盡可能大聲說話但不起作用。 我的任務欄顯示 python 正在使用麥克風但仍然不起作用,我正在使用 vscode。

請所有可以幫助我的人。

顯然,根據您的描述,您的代碼一直在監聽,我認為這就是問題所在。 現在我將在下面給出一個更新的代碼

import speech_recognition as sr

def get_audio():
    print("listening...")
    r = sr.Recognizer()
    with sr.Microphone() as source:
        r.adjust_for_ambient_noise(source, duration = 1)
        audio = r.listen(source)
        said = ""

        try:
            said = r.recognize_google(audio)
            print(said)

        except Exception as e:
            print("Exception: " + str(e))
        
    return said


get_audio()

所以我添加了r.adjust_for_ambient_noise(source, duration = 1)它的作用是,它根據背景噪音調整閾值,然后聽你說什么。

這應該可以正常工作!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM