Added no-voice mode

This commit is contained in:
Mathieu B 2021-08-01 18:23:43 +02:00
parent 5a69b25c10
commit 2fe6ee2e6e
2 changed files with 30 additions and 2 deletions

View File

@ -2,13 +2,14 @@ import os
import struct import struct
import sys import sys
import threading import threading
import time
import pvporcupine import pvporcupine
import pyaudio import pyaudio
import simpleaudio as sa import simpleaudio as sa
import speech_recognition as sr import speech_recognition as sr
from jarvis.utils import server_utils, config_utils, flask_utils from jarvis.utils import server_utils, flask_utils
wake_word_handler = pvporcupine.create(keywords=['jarvis']) wake_word_handler = pvporcupine.create(keywords=['jarvis'])
@ -47,10 +48,21 @@ def record():
server_utils.send_record_to_server(audio.frame_data) server_utils.send_record_to_server(audio.frame_data)
def no_voice_input():
time.sleep(1)
while True:
sentence = input("Write something : ")
server_utils.send_sentence_to_server(sentence)
if __name__ == '__main__': if __name__ == '__main__':
if server_utils.get_server_ip() is None: if server_utils.get_server_ip() is None:
sys.exit(1) sys.exit(1)
if '--no-voice' in sys.argv:
print("[WARN] No voice mode enabled")
thread = threading.Thread(target=no_voice_input).start()
else:
thread = threading.Thread(target=wake_word_listening).start() thread = threading.Thread(target=wake_word_listening).start()
flask_utils.start_server() flask_utils.start_server()

View File

@ -26,6 +26,22 @@ def send_record_to_server(raw_audio_data):
print(bytes.decode(response.content)) print(bytes.decode(response.content))
def send_sentence_to_server(sentence):
url_service = "http://" + str(get_server_ip()) + ":" + str(get_server_port()) + "/process_text_request"
headers = CaseInsensitiveDict()
headers["Content-Type"] = "application/json; charset=utf8"
headers['Client-Ip'] = socket.gethostbyname(socket.gethostname())
headers['Client-Port'] = str(config_utils.get_in_config('PORT'))
# headers["Authorization"] = config_utils.get_in_config("API_KEY")
response = requests.post(url_service,
headers=headers,
json={'sentence': sentence})
print(bytes.decode(response.content))
def get_server_port(): def get_server_port():
return config_utils.get_in_config('SERVER_PORT') if not None else 5000 return config_utils.get_in_config('SERVER_PORT') if not None else 5000