Skip to content

mcornejo/respeaker_python_library

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

88 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ReSpeaker Python Library

Build Status

ReSpeaker is an open project to create voice enabled objects. ReSpeaker python library is an open source python library to provide basic functions of voice interaction.

It uses PocketSphinx for keyword spotting and uses webrtcvad for voice activity detecting.

Installation

python and pip are required.

  1. Install pocketsphinx, webrtcvad

On windows, we can use pre-compiled python wheel packages of pocketsphinx and pyaudio from speech_recognition. For python 2.7, run:

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

On Linux

pip install pocketsphinx webrtcvad
  1. pip install pyaudio respeaker --upgrade

  2. In case the board is not recognised:

apt-get remove --purge python-pip easy_install pip sudo apt-get install portaudio19-dev sudo apt-get install python-pyaudio

sudo pip install -r requirements.txt

Fix the permissions (raspberry pi 0 w): http://stackoverflow.com/questions/3738173/why-does-pyusb-libusb-require-root-sudo-permissions-on-linux

Add: the following line to /lib/udev/rules.d/50-rspk.rules

ACTION=="add", SUBSYSTEMS=="usb", ATTRS{idVendor}=="171b", ATTRS{idProduct}=="2001", MODE="660", GROUP="plugdev"

Then:

sudo adduser pi plugdev sudo udevadm control --reload sudo udevadm trigger

reboot**

Getting started

import logging
import time
from threading import Thread, Event

import fix_import
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.start()
    while True:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            print('Quit')
            quit_event.set()
            break
    thread.join()

if __name__ == '__main__':
    main()

About

To build voice enabled objects/applications with Python and ReSpeaker

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%