spatialaudio / python-sounddevice

:sound: Play and Record Sound with Python :snake:
https://python-sounddevice.readthedocs.io/
MIT License
1.02k stars 149 forks source link

Sounddevice with porcupine not response #468

Open munstr opened 1 year ago

munstr commented 1 year ago

The first version of this code was based on pvrecoder but then errors began to occur and connected sounddevice and the code stopped responding. Doesn't throw any errors. Help me please!

My code:

import pvporcupine
import queue
import sounddevice as sd
import yaml
import sys

with open('tokens.yaml', encoding="utf-8") as f:
    data = yaml.safe_load(f)
    PICOVOICE_TOKEN = data[0].get("Picovoice")

porcupine = pvporcupine.create(
  access_key=PICOVOICE_TOKEN,
  keyword_paths=[r'C:\Users\lsiba\OneDrive\Desktop\CODS\jarvis\jarvis_windows.ppn'],
  sensitivities=[1]
)
#print(sd.query_devices())
device_info = sd.query_devices(sd.default.device[0], 'input')
samplerate = int(device_info['default_samplerate'])
q = queue.Queue()

def recordCallback(indata, frames, time, status):
    if status:
        print(status, file=sys.stderr)
    q.put(bytes(indata))

def wake_word():
    with sd.RawInputStream(dtype='int16',
                        blocksize = 256,
                        channels=1,
                        callback=recordCallback):

        global cont
        cont = True
        while cont==True:
            data = q.get() 
            keyword_index = porcupine.process(data)
            if keyword_index >= 0:
                cont = False
                print("WAKE")
                return "WAKE"

wake_word()
HaHeho commented 1 year ago

Please edit your comment to provide valid and Markdown formatting for Python code according to the Contribution guidelines! :)

munstr commented 1 year ago

Ok. Can you help me?

mgeier commented 1 year ago

errors began to occur

Please describe which errors did occur.

Please describe how you started your script.

Please describe what "pvrecoder" and "pvporcupine" even is.

Please tell us what you want to do.

As @HaHeho mentioned, it would be very helpful if you would follow the contribution guidelines.

the code stopped responding

Can you please try to find the line of code where it stopps responding?