Fix bug program would open outside pycharm

This commit is contained in:
Mathieu 2021-08-22 18:49:20 +02:00
parent d1fe531ddf
commit 9a24d30b0a
5 changed files with 24 additions and 7 deletions

View File

@ -1,4 +1,5 @@
{ {
"PORT": 5001, "PORT": 5001,
"SERVER_PORT": 5000 "SERVER_PORT": 5000,
"SERVER_IP": "192.168.1.130"
} }

View File

@ -33,7 +33,7 @@ def wake_word_listening():
if keyword_index >= 0: if keyword_index >= 0:
threading.Thread( threading.Thread(
target=sa.WaveObject.from_wave_file(os.getcwd() + "/sounds/" + "listening.wav").play).start() target=sa.WaveObject.from_wave_file(os.getcwd() + "/jarvis" + "/sounds/" + "listening.wav").play).start()
record() record()
@ -44,7 +44,7 @@ def record():
r.adjust_for_ambient_noise(source=source, duration=0.7) r.adjust_for_ambient_noise(source=source, duration=0.7)
audio = r.listen(source, timeout=2, phrase_time_limit=5) 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() threading.Thread(target=sa.WaveObject.from_wave_file(os.getcwd() + "/jarvis" + "/sounds/" + "listened.wav").play).start()
server_utils.send_record_to_server(audio.frame_data) server_utils.send_record_to_server(audio.frame_data)
@ -55,14 +55,14 @@ def no_voice_input():
server_utils.send_sentence_to_server(sentence) server_utils.send_sentence_to_server(sentence)
if __name__ == '__main__': def start():
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: if '--no-voice' in sys.argv:
print("[WARN] No voice mode enabled") print("[WARN] No voice mode enabled")
thread = threading.Thread(target=no_voice_input).start() threading.Thread(target=no_voice_input).start()
else: else:
thread = threading.Thread(target=wake_word_listening).start() threading.Thread(target=wake_word_listening).start()
flask_utils.start_server() flask_utils.start_server()

View File

@ -1,7 +1,7 @@
import json import json
import os import os
path = os.getcwd() path = os.getcwd() + "/jarvis"
def get_in_config(name): def get_in_config(name):

View File

@ -73,6 +73,11 @@ def find_server_on_network():
ip = socket.gethostbyname(socket.gethostname()) ip = socket.gethostbyname(socket.gethostname())
# sometimes it might return the local ip (127.0.0.1) adding local should solves that
# TODO: see if we only use the ".local" ip
if ip.startswith("127.0"):
ip = socket.gethostbyname(socket.gethostname() + ".local")
if ip.startswith("192.168.1"): if ip.startswith("192.168.1"):
server_ip = find_device_on_network_with_opened_port(ipaddress.ip_network("192.168.1.0/24"), server_ip = find_device_on_network_with_opened_port(ipaddress.ip_network("192.168.1.0/24"),
config_utils.get_in_config('SERVER_PORT')) config_utils.get_in_config('SERVER_PORT'))

11
run.py Normal file
View File

@ -0,0 +1,11 @@
import os
import sys
# TODO: see if something better could be done
if __name__ == '__main__':
sys.path.append(os.path.realpath('..'))
# doing the import after editing the path otherwise cause issue between running in pycharm or the terminal
from jarvis.main import start
start()