Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: object of type 'NoneType' has no len() #255

Closed
itsmespydy opened this issue Jan 13, 2020 · 3 comments
Closed

TypeError: object of type 'NoneType' has no len() #255

itsmespydy opened this issue Jan 13, 2020 · 3 comments

Comments

@itsmespydy
Copy link

itsmespydy commented Jan 13, 2020

Mycode :
import sys
import soundfile
import os
import pyaudio
sys.path.append(r'C:\Users\Mashud A Talukdar\AppData\Local\Programs\Python\Python36\Lib\site-packages\porcupine\binding\python')
from porcupine import Porcupine

library_path= 'C:\Users\Mashud A Talukdar\AppData\Local\Programs\Python\Python36\Lib\site-packages\porcupine\lib\windows\amd64\libpv_porcupine.dll'
model_file_path='C:\Users\Mashud A Talukdar\AppData\Local\Programs\Python\Python36\Lib\site-packages\porcupine\lib\common\porcupine_params.pv'
keyword_file_paths=['C:\Users\Mashud A Talukdar\AppData\Local\Programs\Python\Python36\Lib\site-packages\porcupine\resources\keyword_files\windows\alexa_windows.ppn']
sensitivities=[0.5]
handle = Porcupine(library_path, model_file_path, keyword_file_paths=keyword_file_paths, sensitivities=sensitivities)
def get_next_audio_frame():
pass

while True:
pcm = get_next_audio_frame()
keyword_index = handle.process(pcm)
if keyword_index >= 0:
# detection event logic/callback
pass

output :
File "c:/Users/Mashud A Talukdar/Desktop/Python/test.py", line 18, in
keyword_index = handle.process(pcm)
File "C:\Users\Mashud A Talukdar\AppData\Local\Programs\Python\Python36\lib\site-packages\porcupine\binding\python\porcupine.py", line 154, in process
status = self.process_func(self._handle, (c_short * len(pcm))(*pcm), byref(result))
TypeError: object of type 'NoneType' has no len()

please help me sir
i am working on college project and i need a hotword detection in my python project to start my project

@kenarsa
Copy link
Member

kenarsa commented Jan 13, 2020

you need to implement "def get_next_audio_frame()" yourself for you platform. it is returning nothing now.

@kenarsa kenarsa closed this as completed Jan 13, 2020
@justUmen
Copy link

justUmen commented Jul 9, 2021

I think the SDK python README should have at least a workable example that everybody can use/edit easily.
Like this one for example.

#!/usr/bin/env python3
import struct
import pyaudio
import pvporcupine
print(pvporcupine.KEYWORDS)

porcupine = None
pa = None
audio_stream = None

try:
    porcupine = pvporcupine.create(keywords=["picovoice", "blueberry"])

    pa = pyaudio.PyAudio()

    audio_stream = pa.open(
                    rate=porcupine.sample_rate,
                    channels=1,
                    format=pyaudio.paInt16,
                    input=True,
                    frames_per_buffer=porcupine.frame_length)

    while True:
        pcm = audio_stream.read(porcupine.frame_length)
        pcm = struct.unpack_from("h" * porcupine.frame_length, pcm)

        keyword_index = porcupine.process(pcm)

        if keyword_index >= 0:
            print("Hotword Detected")
finally:
    if porcupine is not None:
        porcupine.delete()

    if audio_stream is not None:
        audio_stream.close()

    if pa is not None:
            pa.terminate()

@kenarsa
Copy link
Member

kenarsa commented Jul 9, 2021

@Picovoice Picovoice locked as off-topic and limited conversation to collaborators Jul 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants