Skip to content

Commit

Permalink
cleaned up a bit, more info on the HID library
Browse files Browse the repository at this point in the history
  • Loading branch information
bwhitman committed Jan 27, 2017
1 parent 7512a65 commit fa4683d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
8 changes: 4 additions & 4 deletions README.md
@@ -1,12 +1,12 @@
# respeaker-xmos-hid

Python & C hidapi examples for the "Respeaker" microphone array to show angle & VAD information
Python & C hidapi examples for the "Respeaker" microphone array to show angle & voice activity (VAD) information.

For both, you need to install hidapi
For both, you need to install [hidapi.](https://github.com/signal11/hidapi)

For Python, you need this [hidapi wrapper](https://pypi.python.org/pypi/hid).
For Python, you need this [hidapi wrapper](https://pypi.python.org/pypi/hidapi). (Note: there are two python modules called hid, this is the one you get by pip install hidapi. The other probably works too but has different calling conventions.)

The Python example records 10 seconds to a wave file and prints out VAD and voice angle information in real time to the screen.
The Python example records 10 seconds to a wave file called output.wav and prints out VAD and voice angle information in real time to the screen. Just plug the mic array directly over USB to your computer and run the script.

```
carry:respeaker-xmos-hid bwhitman$ python listen_and_get_position.py
Expand Down
14 changes: 6 additions & 8 deletions listen_and_get_position.py
@@ -1,17 +1,15 @@
import wave, os, pyaudio, time, hid
import wave, os, pyaudio, time
import hid # https://pypi.python.org/pypi/hidapi aka https://github.com/trezor/cython-hidapi

_pyaudio_instance = pyaudio.PyAudio()
_wav = None
RESPEAKER_VENDOR_ID = 0x2886
RESPEAKER_PRODUCT_ID = 0x07
RECORD_SR = 16000

# Set up the HID driver, you have to open it by path so we look it up first by VID and PID
_dev = hid.device(vendor_id = RESPEAKER_VENDOR_ID, product_id = RESPEAKER_PRODUCT_ID)
for x in hid.enumerate():
if x['vendor_id'] == RESPEAKER_VENDOR_ID and x['product_id'] == RESPEAKER_PRODUCT_ID:
_dev.open_path(x['path'])

# Set up the HID driver
_dev = hid.device()
_dev.open(RESPEAKER_VENDOR_ID, RESPEAKER_PRODUCT_ID)

# Write data to a register, return how many bytes were written
def write_register(register, data):
Expand Down Expand Up @@ -106,7 +104,7 @@ def main():
# And test writing a register, the LED -- I turn them off, saves ~120 mA
write_register(0, [0, 0, 0, 0]) # mode, b, g, r -- mode 0 is "all off"
# Now record audio to a wav file for 10 seconds and print VAD and angle to screen
record()
record(length_seconds = 10)

if __name__ == '__main__':
main()

0 comments on commit fa4683d

Please sign in to comment.