-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
60 lines (50 loc) · 1.79 KB
/
Copy pathexample.py
File metadata and controls
60 lines (50 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import openwakeword
import numpy as np
import pyaudio
import time
# Инициализация модели с вашей кастомной моделью
oww = openwakeword.Model(
wakeword_model_paths=["vasya.onnx"],
enable_speex_noise_suppression=True,
vad_threshold=0.5
)
# Параметры аудиопотока
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 16000
CHUNK = 1280 # 1280 samples at 16kHz is 80ms
audio = pyaudio.PyAudio()
# Открытие потока
stream = audio.open(
format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK
)
# Переменные для отслеживания состояния
last_activation = time.time()
cooldown = 1.0 # секунды между активациями
try:
while True:
# Чтение аудио данных
audio_data = np.frombuffer(stream.read(CHUNK), dtype=np.int16)
# Получение предсказаний
prediction = oww.predict(audio_data)
# Проверка активации
if prediction['vasya'] > 0.8:
current_time = time.time()
if current_time - last_activation > cooldown:
last_activation = current_time
confidence = prediction['vasya']
print(f"\nАКТИВАЦИЯ! Уверенность: {confidence:.2f}")
print("Команда распознана!")
# Здесь можно добавить выполнение действия
# Вывод прогресс-бара
print(".", end="", flush=True)
time.sleep(0.05)
except KeyboardInterrupt:
print("\nТест остановлен")
stream.stop_stream()
stream.close()
audio.terminate()