Added simpleaudio lib for listening/listened sound on hot word recogniton

This commit is contained in:
Mathieu B 2021-07-31 20:31:19 +02:00
parent 8733e5f38a
commit ada1849ee0
4 changed files with 9 additions and 4 deletions

View File

@ -1,7 +1,10 @@
import os
import struct
import threading
import pvporcupine
import pyaudio
import simpleaudio as sa
import speech_recognition as sr
from jarvis.utils import server_utils, config_utils
@ -27,7 +30,8 @@ def wake_word_listening():
keyword_index = wake_word_handler.process(pcm)
if keyword_index >= 0:
print("Recognized")
threading.Thread(
target=sa.WaveObject.from_wave_file(os.getcwd() + "/sounds/" + "listening.wav").play).start()
record()
@ -35,10 +39,10 @@ def record():
# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
print("Say something!")
r.adjust_for_ambient_noise(source=source, duration=0.5)
r.adjust_for_ambient_noise(source=source, duration=0.7)
audio = r.listen(source, timeout=2, phrase_time_limit=5)
threading.Thread(target=sa.WaveObject.from_wave_file(os.getcwd() + "/sounds/" + "listened.wav").play).start()
server_utils.send_record_to_server(audio.frame_data)

BIN
jarvis/sounds/listened.wav Normal file

Binary file not shown.

BIN
jarvis/sounds/listening.wav Normal file

Binary file not shown.

View File

@ -2,3 +2,4 @@ pvporcupine~=1.9.5
PyAudio~=0.2.11
SpeechRecognition~=3.8.1
requests~=2.26.0
simpleaudio~=1.0.4