使用 python 和ReSpeaker构建启用语音的对象/应用程序

・2 分钟阅读

  • 源代码名称: respeaker_python_library
  • 源代码网址: https://www.github.com/respeaker/respeaker_python_library
  • respeaker_python_library的文档
  • respeaker_python_library的源代码下载
  • Git URL:
    git://www.github.com/respeaker/respeaker_python_library.git
  • Git Clone代码到本地:
    git clone https://www.github.com/respeaker/respeaker_python_library
  • Subversion代码到本地:
    $ svn co --depth empty https://www.github.com/respeaker/respeaker_python_library
                              Checked out revision 1.
                              $ cd repo
                              $ svn up trunk
              
  • ReSpeaker python-库

    Build Status

    ReSpeaker 是一个开放项目,用于创建启用语音的对象。 ReSpeaker python 库是一个开源 python 库,提供语音交互的基本功能。

    安装( 不适用于ReSpeaker内核)

    注意:默认情况下,ReSpeaker内核上已经安装了这个库。 请跳过安装步骤,不要安装它

    需要 pythonpip

    • 安装 pocketsphinx,webrtcvad

    在 Windows 上,我们可以从 speech_recognition 使用pocketsphinx和pyaudio的预编译 python 包。 对于 python 2.7,运行:

    
    pip install https://github.com/respeaker/respeaker_python_library/releases/download/v0.4.1/pocketsphinx-0.0.9-cp27-cp27m-win32.whl
    
    
    pip install https://github.com/respeaker/respeaker_python_library/releases/download/v0.4.1/webrtcvad-2.0.9.dev0-cp27-cp27m-win32.whl
    
    
    
    

    在Linux上

    
    pip install pocketsphinx webrtcvad
    
    
    
    

    pip install pyaudio respeaker --upgrade

    安装 hidapi ( 可选)

    这个步骤在OSX上是必需的。

    启动

    
    import logging
    
    
    import time
    
    
    from threading import Thread, Event
    
    
    
    from respeaker import Microphone
    
    
    
    def task(quit_event):
    
    
     mic = Microphone(quit_event=quit_event)
    
    
    
     while not quit_event.is_set():
    
    
     if mic.wakeup('respeaker'):
    
    
     print('Wake up')
    
    
     data = mic.listen()
    
    
     text = mic.recognize(data)
    
    
     if text:
    
    
     print('Recognized %s' % text)
    
    
    
    def main():
    
    
     logging.basicConfig(level=logging.DEBUG)
    
    
    
     quit_event = Event()
    
    
     thread = Thread(target=task, args=(quit_event,))
    
    
     thread.daemon = True
    
    
     thread.start()
    
    
     while True:
    
    
     try:
    
    
     time.sleep(1)
    
    
     except KeyboardInterrupt:
    
    
     print('Quit')
    
    
     quit_event.set()
    
    
     break
    
    
     time.sleep(1)
    
    
    
    if __name__ == '__main__':
    
    
     main()
    
    
    
    
    讨论
    Fansisi profile image