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

Using microphone detection #92

Open
vedbobo opened this issue Apr 25, 2024 · 1 comment
Open

Using microphone detection #92

vedbobo opened this issue Apr 25, 2024 · 1 comment

Comments

@vedbobo
Copy link

vedbobo commented Apr 25, 2024

import webrtcvad
import pyaudio
import os
CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 16000
WAVE_OUTPUT_DIR = "temp"

if not os.path.exists(WAVE_OUTPUT_DIR):
os.makedirs(WAVE_OUTPUT_DIR)
WAVE_OUTPUT_FILENAME = os.path.join(WAVE_OUTPUT_DIR, "output.wav")

p = pyaudio.PyAudio()
vad = webrtcvad.Vad(1)

stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK)

frames = []
print("start...")
while True:
data = stream.read(CHUNK)
is_speech = vad.is_speech(data, sample_rate = RATE)
if is_speech:
frames.append(data)
else:
break
print("end...")
stream.stop_stream()
stream.close()
p.terminate()

Prompt:Error while processing frame

is_speech = vad.is_speech(data, sample_rate = RATE) How to handle this data

@Wetosi
Copy link

Wetosi commented May 1, 2024

Instead of "data = stream.read(CHUNK)", do "data = stream.read(int(RATE/100))".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants