python-sounddevice icon indicating copy to clipboard operation
python-sounddevice copied to clipboard

Sounddevice with porcupine not response

Open munstr opened this issue 2 years ago • 3 comments

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()

munstr avatar May 14 '23 17:05 munstr

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

HaHeho avatar May 14 '23 17:05 HaHeho

Ok. Can you help me?

munstr avatar May 15 '23 12:05 munstr

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?

mgeier avatar May 15 '23 22:05 mgeier