mirror of
https://github.com/MarkParker5/STARK.git
synced 2024-11-24 08:12:13 +02:00
test background + inactive + needs input
This commit is contained in:
parent
21ecb5c9ef
commit
23fa5ba075
@ -57,6 +57,7 @@ class VoiceAssistant(SpeechRecognizerDelegate, CommandsContextDelegate):
|
||||
response = self._responses.pop(0)
|
||||
self._play_response(response)
|
||||
self.commands_context.add_context(CommandsContextLayer(response.commands, response.parameters))
|
||||
print('Left:', [r.text for r in self._responses])
|
||||
if response.needs_user_input:
|
||||
break
|
||||
|
||||
|
@ -112,6 +112,38 @@ def commands_context_flow() -> tuple[CommandsContext, CommandsContextDelegateMoc
|
||||
text = voice = 'Finished long background task'
|
||||
return Response(text = text, voice = voice)
|
||||
|
||||
@manager.new('background multiple contexts')
|
||||
@manager.background(Response(text = 'Starting long background task'))
|
||||
def background_multiple_contexts(handler: ResponseHandler):
|
||||
|
||||
|
||||
|
||||
text = voice = 'Finished long background task'
|
||||
return Response(text = text, voice = voice)
|
||||
|
||||
@manager.new('background needs input')
|
||||
@manager.background(Response(text = 'Starting long background task'))
|
||||
def background_needs_input(handler: ResponseHandler):
|
||||
time.sleep(0.01)
|
||||
|
||||
for text in ['First response', 'Second response', 'Third response']:
|
||||
handler.process_response(Response(text = text, voice = text))
|
||||
|
||||
text = 'Needs input'
|
||||
handler.process_response(Response(text = text, voice = text, needs_user_input = True))
|
||||
|
||||
for text in ['Fourth response', 'Fifth response', 'Sixth response']:
|
||||
handler.process_response(Response(text = text, voice = text))
|
||||
|
||||
text = voice = 'Finished long background task'
|
||||
return Response(text = text, voice = voice)
|
||||
|
||||
@manager.new('background remove response')
|
||||
@manager.background(Response(text = 'Starting long background task'))
|
||||
def background_remove_response():
|
||||
|
||||
text = voice = 'Finished long background task'
|
||||
return Response(text = text, voice = voice)
|
||||
|
||||
return context, context_delegate
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
import time
|
||||
from datetime import datetime
|
||||
import config
|
||||
|
||||
@ -65,4 +66,47 @@ def test_background_command_with_afk_mode(voice_assistant):
|
||||
voice_assistant.speech_recognizer_did_receive_final_result('hello world')
|
||||
assert len(voice_assistant.speech_synthesizer.results) == 2
|
||||
assert voice_assistant.speech_synthesizer.results.pop(0).text == 'Hello, world!'
|
||||
assert voice_assistant.speech_synthesizer.results.pop(0).text == 'Finished background task'
|
||||
assert voice_assistant.speech_synthesizer.results.pop(0).text == 'Finished background task'
|
||||
|
||||
def test_background_inactive_needs_input(voice_assistant):
|
||||
voice_assistant.speech_recognizer_did_receive_final_result('background needs input')
|
||||
assert len(voice_assistant.commands_context._threads) == 1
|
||||
|
||||
# force inactive mode by settings zero time
|
||||
voice_assistant._last_interaction_time = datetime.fromtimestamp(0)
|
||||
|
||||
# wait for thread to finish
|
||||
voice_assistant.commands_context._threads[0].thread.join()
|
||||
|
||||
# receive context output
|
||||
voice_assistant.commands_context._check_threads()
|
||||
|
||||
# voice assistant should receive all but not say anything
|
||||
assert len(voice_assistant._responses) == 8
|
||||
assert len(voice_assistant.speech_synthesizer.results) == 8
|
||||
voice_assistant.speech_synthesizer.results.clear()
|
||||
|
||||
# interact to disable inactive mode
|
||||
voice_assistant.speech_recognizer_did_receive_final_result('hello world')
|
||||
|
||||
# voice assistant should say all responses until needs input
|
||||
assert len(voice_assistant.speech_synthesizer.results) == 5
|
||||
assert len(voice_assistant._responses) == 4
|
||||
|
||||
for response in ['Hello, world!', 'First response', 'Second response', 'Third response', 'Needs input']:
|
||||
assert voice_assistant.speech_synthesizer.results.pop(0).text == response
|
||||
|
||||
# interact to emulate user input and continue repeating responses
|
||||
voice_assistant.speech_recognizer_did_receive_final_result('hello world')
|
||||
|
||||
# voice assistant should say all left responses
|
||||
assert len(voice_assistant.speech_synthesizer.results) == 5
|
||||
assert len(voice_assistant._responses) == 0
|
||||
for response in ['Hello, world!', 'Fourth response', 'Fifth response', 'Sixth response', 'Finished long background task']:
|
||||
assert voice_assistant.speech_synthesizer.results.pop(0).text == response
|
||||
|
||||
def test_background_inactive_with_context(voice_assistant):
|
||||
pass
|
||||
|
||||
def test_background_inactive_remove_response(voice_assistant):
|
||||
pass
|
||||
|
Loading…
Reference in New Issue
Block a user