首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python 3和Pocket Sphinx

Python 3和Pocket Sphinx
EN

Stack Overflow用户
提问于 2017-11-26 04:30:36
回答 0查看 179关注 0票数 3

我正在尝试为我的祖父创建一个简单的音乐播放器,我的祖父通过编程一个音频控制的音乐播放器来解决按钮问题。我在Python 3和Pocket Sphinx上使用Raspberry Pi 3。因为Pocket Sphinx不需要Internet,所以我将使用它,因为我的祖父无法访问Internet。

我的问题是如何获取一个“说”的值,例如:“播放按钮”,并让它播放wave文件" Button“?

以下是我构建基本程序所需的内容:

代码语言:javascript
复制
import speech_recognition as sr
import pygame
from pygame import mixer
mixer.init()

r = sr.Recognizer()
m = sr.Microphone()

Button = pygame.mixer.Sound('/home/pi/Downloads/button8.wav')

try:
    print("A moment of silence, please...")
    with m as source: r.adjust_for_ambient_noise(source)
    print("Set minimum energy threshold to {}".format(r.energy_threshold))
    while True:
        print("Say something!")
        with m as source: audio = r.listen(source)
        print("Got it! Now to recognize it...")
        try:
            # recognize speech using Sphinx
            value = r.recognize_sphinx(audio)
            print("You said {}".format(value)) #uses unicode for strings and this is where I am stuck
            pygame.mixer.Sound.play(Button)
            pygame.mixer.music.stop()
        except sr.UnknownValueError:
            print("Oops! Didn't catch that")
        except sr.RequestError as e:
            print("Uh oh! Couldn't request results; {0}".format(e))
except KeyboardInterrupt:
    pass

非常感谢您能提供的任何帮助。我是个初学者,请多多关照。

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47490242

复制
相关文章

相似问题

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