diff --git a/stark/__init__.py b/stark/__init__.py index e69de29..321c508 100644 --- a/stark/__init__.py +++ b/stark/__init__.py @@ -0,0 +1,31 @@ +import asyncer + +from stark.interfaces.protocols import SpeechRecognizer, SpeechSynthesizer +from stark.core import CommandsContext, CommandsManager +from stark.voice_assistant import VoiceAssistant +from stark.general.blockage_detector import BlockageDetector + + +async def run( + manager: CommandsManager, + speech_recognizer: SpeechRecognizer, + speech_synthesizer: SpeechSynthesizer +): + async with asyncer.create_task_group() as main_task_group: + context = CommandsContext( + task_group = main_task_group, + commands_manager = manager + ) + voice_assistant = VoiceAssistant( + speech_recognizer = speech_recognizer, + speech_synthesizer = speech_synthesizer, + commands_context = context + ) + speech_recognizer.delegate = voice_assistant + context.delegate = voice_assistant + + main_task_group.soonify(speech_recognizer.start_listening)() + main_task_group.soonify(context.handle_responses)() + + detector = BlockageDetector(threshold = 1) + main_task_group.soonify(detector.monitor)() diff --git a/stark/__main__.py b/stark/__main__.py deleted file mode 100644 index 53331dd..0000000 --- a/stark/__main__.py +++ /dev/null @@ -1,68 +0,0 @@ -import anyio -import asyncer - -from stark.core import CommandsContext, CommandsManager, Response -from stark.interfaces.silero import SileroSpeechSynthesizer -from stark.interfaces.vosk import VoskSpeechRecognizer -from stark.voice_assistant import VoiceAssistant -from stark.general.blockage_detector import BlockageDetector -# from stark.types import Number, String -import config - - -manager = CommandsManager() - -@manager.new('привет') -def hello_world(): - return Response( - text = 'Hello 10 times', - voice = 'Привет, мир!, Привет, мир!, Привет, мир!, Привет, мир!, Привет, мир!, Привет, мир!, Привет, мир!, Привет, мир!, Привет, мир!, Привет, мир!, Привет, мир!' - ) - -@manager.new('пока') -async def by_world(): - import time - time.sleep(1.5) # simulate blocking operation - return Response( - text = 'Прощай, мир!', - voice = 'Прощай, мир!' - ) - -@manager.new('фоновый режим') -def by_world_sync_bg(): - import time - time.sleep(6) # simulate blocking operation - return Response( - text = 'Прощай, мир!', - voice = 'Прощай, мир!' - ) - -async def main(): # manager: CommandsManager, speech_recognizer: SpeechRecognizer, speech_synthesizer: SpeechSynthesizer): - async with asyncer.create_task_group() as main_task_group: - - sr = VoskSpeechRecognizer( - model_url = config.vosk_model_url - ) - stt = SileroSpeechSynthesizer( - model_url = config.silero_model_url - ) - cc = CommandsContext( - task_group = main_task_group, - commands_manager = manager - ) - va = VoiceAssistant( - speech_recognizer = sr, - speech_synthesizer = stt, - commands_context = cc - ) - sr.delegate = va - cc.delegate = va - - main_task_group.soonify(sr.start_listening)() - main_task_group.soonify(cc.handle_responses)() - - detector = BlockageDetector(threshold = 1) - main_task_group.soonify(detector.monitor)() - -if __name__ == '__main__': - anyio.run(main) diff --git a/stark/config.py b/stark/config.py deleted file mode 100644 index c4a7e4a..0000000 --- a/stark/config.py +++ /dev/null @@ -1,15 +0,0 @@ - -# Vosk Speech Recognition -vosk_model_url: str = 'https://alphacephei.com/vosk/models/vosk-model-small-ru-0.22.zip' - -# Google Cloud TTS -goole_tts_json_key: str = 'downloads/gc-tts-key.json' -language_code: str = 'ru-RU' -voice_name: str = 'ru-RU-Wavenet-B' - -# Silero TTS -silero_model_url: str = 'https://models.silero.ai/models/tts/ru/ru_v3.pt' - -# Picovoice Porcupine (Wakeword) -porcupine_key: str = '' -porcupine_keyword_path: str = 'downloads/porcupine-keywords.txt'