summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBotond Hende <nettingman@gmail.com>2024-11-20 13:46:44 +0100
committerBotond Hende <nettingman@gmail.com>2024-11-20 13:46:44 +0100
commita54f9cbed78ce3df4252c209553f4f318bc2b81e (patch)
tree138fcc62d161fe07d47d35ecd99043f2ffc340bd
parenta7448c94421b6ac874d33a5e0b4f8731931dad3e (diff)
cleanup pipo when exiting
-rw-r--r--__main__.py31
-rw-r--r--modules/input_handlers/pipewire_record.py11
2 files changed, 25 insertions, 17 deletions
diff --git a/__main__.py b/__main__.py
index 4aa3117..b51e70b 100644
--- a/__main__.py
+++ b/__main__.py
@@ -3,12 +3,13 @@ import sys
import yaml
from pathlib import Path
+
from .modules.config import load_config
from .modules.hassil.recognize import recognize
from .modules.hassil.util import merge_dict
from .modules.hassil.intents import Intents, TextSlotList
from .modules.input_handlers.stdin_input import get_input_stdin
-from .modules.input_handlers.pipewire_record import get_input_pw_record
+from .modules.input_handlers.pipewire_record import get_input_pw_record, cleanup
from .modules.intents import *
@@ -39,18 +40,22 @@ def main():
intents = Intents.from_dict(input_dict)
- for input_text in get_input_pw_record():
- result = recognize(input_text, intents, slot_lists=slot_lists)
- if result is not None:
- result_dict = {
- "intent": result.intent.name,
- **{e.name: e.value for e in result.entities_list},
- }
- print(result_dict)
- handler = getattr(globals()[result_dict["domain"]], result_dict["intent"])
- handler(result_dict, config)
- else:
- print("<no match>")
+ try:
+ # TODO select input type from config
+ for input_text in get_input_pw_record():
+ result = recognize(input_text, intents, slot_lists=slot_lists)
+ if result is not None:
+ result_dict = {
+ "intent": result.intent.name,
+ **{e.name: e.value for e in result.entities_list},
+ }
+ print(result_dict)
+ handler = getattr(globals()[result_dict["domain"]], result_dict["intent"])
+ handler(result_dict, config)
+ else:
+ print("<no match>")
+ finally:
+ cleanup()
if __name__ == '__main__':
main() \ No newline at end of file
diff --git a/modules/input_handlers/pipewire_record.py b/modules/input_handlers/pipewire_record.py
index 8584ad3..147d77b 100644
--- a/modules/input_handlers/pipewire_record.py
+++ b/modules/input_handlers/pipewire_record.py
@@ -9,12 +9,15 @@ import whisper
FIFO_PATH = "/tmp/hestia-listening"
RECORD_PATH = "/tmp/hestia-record.mp3"
-def get_input_pw_record():
- device = get_device()
-
+def cleanup():
if os.path.exists(FIFO_PATH):
os.remove(FIFO_PATH)
+
+def get_input_pw_record():
+ device = get_device()
+
+ cleanup()
os.mkfifo(FIFO_PATH)
while True:
@@ -33,7 +36,7 @@ def get_input_pw_record():
ps.kill()
# TODO "error"
# TODO exit gracefully or try to recover
- sys.exit()
+ raise StopIteration
model = whisper.load_model("base")