首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SnowBoy热词检测问题

SnowBoy热词检测问题
EN

Stack Overflow用户
提问于 2019-02-08 23:56:09
回答 1查看 381关注 0票数 0

大家好,我正试图在我的代码中触发while循环,每当说到"virgo“这个热词时,它就会启动语音识别。问题是snowboy检测到了hotword,但是一旦hotword被触发,我不知道如何执行"while“循环。有什么需要帮忙的吗?这听起来可能很愚蠢,应该相对容易,但我的大脑现在着火了。谢谢!

代码语言:javascript
复制
import speech_recognition as sr
from textblob import TextBlob
import snowboydecoder

recognizer_instance = sr.Recognizer()

def detected_callback():
    print ("tell me!")

detector = snowboydecoder.HotwordDetector("virgo.pmdl",sensitivity=0.5)

detector.start(detected_callback=snowboydecoder.play_audio_file,sleep_time=0.03)
detector.terminate()


while True:
    with sr.Microphone() as source:
        recognizer_instance.adjust_for_ambient_noise(source)
        print("Listening...")
        audio = recognizer_instance.listen(source)
        print("copy that!")

    try:
        text = recognizer_instance.recognize_google(audio, language = "it-IT")
        print("you said:\n", text) 

    except Exception as e:
        break
EN

回答 1

Stack Overflow用户

发布于 2019-02-09 04:12:42

给定TRUE,你的while循环总是被“触发”的,直到你break退出它。要触发循环内的代码,请执行以下操作:

代码语言:javascript
复制
while True:
    if YOUR_TRIGGER_CONDITION:
        with sr.Microphone() as source:
            recognizer_instance.adjust_for_ambient_noise(source)
            print("Listening...")
            audio = recognizer_instance.listen(source)
            print("copy that!")

        try:
            text = recognizer_instance.recognize_google(audio, language = "it-IT")
            print("you said:\n", text) 

        except Exception as e:
            break
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54596076

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档