예제 #1
0
def test_dispatch():
    stages = [
        mock.MagicMock(),
        mock.MagicMock(),
        mock.MagicMock(),
    ]
    pipeline = SpeechPipeline(mock.MagicMock(), stages=stages)

    pipeline.start()

    pipeline._dispatch()
예제 #2
0
def test_activate_deactivate():
    stages = [
        mock.MagicMock(),
        mock.MagicMock(),
        mock.MagicMock(),
    ]
    pipeline = SpeechPipeline(mock.MagicMock(), stages=stages)

    pipeline.start()
    pipeline.activate()
    assert pipeline.context.is_active

    pipeline.deactivate()
    assert not pipeline.context.is_active
예제 #3
0
def test_run():
    stages = [
        mock.MagicMock(),
        mock.MagicMock(),
        mock.MagicMock(),
    ]
    pipeline = SpeechPipeline(mock.MagicMock(), stages=stages)

    @pipeline.event
    def on_step(context):
        pipeline.stop()

    pipeline.start()
    pipeline.run()
예제 #4
0
def test_cleanup():
    stages = [
        mock.MagicMock(),
        mock.MagicMock(),
        mock.MagicMock(),
    ]
    pipeline = SpeechPipeline(mock.MagicMock(), stages=stages)

    pipeline.start()
    assert pipeline.is_running

    pipeline.stop()
    assert not pipeline.is_running

    pipeline.cleanup()
    assert not pipeline._stages
    assert not pipeline._input_source
예제 #5
0
def test_cleanup():
    stages = [
        mock.MagicMock(),
        mock.MagicMock(),
        mock.MagicMock(),
    ]
    pipeline = SpeechPipeline(mock.MagicMock(), stages=stages)

    pipeline.start()
    assert pipeline.is_running

    pipeline.stop()
    assert not pipeline.is_running

    # run after stopped will trigger clean up
    pipeline.run()
    assert not pipeline._stages
    assert not pipeline._input_source
예제 #6
0
def test_start_stop():
    stages = [
        mock.MagicMock(),
        mock.MagicMock(),
        mock.MagicMock(),
    ]
    pipeline = SpeechPipeline(mock.MagicMock(), stages=stages)

    pipeline.start()
    assert pipeline.is_running

    # test second call to start, which ignores if the pipeline is running
    pipeline.start()

    pipeline.step()

    pipeline.close()
    assert not pipeline.is_running
예제 #7
0
def test_pause_resume():
    stages = [
        mock.MagicMock(),
        mock.MagicMock(),
        mock.MagicMock(),
    ]
    pipeline = SpeechPipeline(mock.MagicMock(), stages=stages)

    pipeline.start()
    assert pipeline.is_running

    pipeline.step()
    pipeline.pause()
    pipeline._input_source.stop.assert_called()

    # verify it does nothing
    pipeline.step()

    pipeline.resume()
    pipeline._input_source.start.assert_called()
    pipeline.close()
예제 #8
0
def main():
    pipeline = SpeechPipeline(
        PyAudioInput(frame_width=20,
                     sample_rate=16000,
                     exception_on_overflow=False),
        [
            VoiceActivityDetector(),
            WakewordTrigger(pre_emphasis=0.97, model_dir="tflite"),
            GoogleSpeechRecognizer(GOOGLE_CREDS),
            ActivationTimeout(),
        ],
    )

    dialogue_manager = DialogueManager(
        "tflite", "distilbert-base-cased-distilled-squad")
    manager = TextToSpeechManager(
        TextToSpeechClient(KEY_ID, KEY_SECRET),
        PyAudioOutput(),
    )

    @pipeline.event
    def on_activate(context):
        print(context.is_active)

    @pipeline.event
    def on_recognize(context):
        pipeline.pause()
        answer = dialogue_manager(context.transcript)
        manager.synthesize(answer, "text", "demo-male")
        pipeline.resume()

    @pipeline.event
    def on_deactivate(context):
        print(context.is_active)

    manager.synthesize(dialogue_manager.greet(), "text", "demo-male")
    pipeline.start()
    pipeline.run()
예제 #9
0
def main():
    pipeline = SpeechPipeline(
        PyAudioInput(frame_width=20, sample_rate=16000, exception_on_overflow=False),
        [
            VoiceActivityDetector(),
            WakewordTrigger(pre_emphasis=0.97, model_dir="tflite"),
            CloudSpeechRecognizer(spokestack_id=KEY_ID, spokestack_secret=KEY_SECRET),
            ActivationTimeout(),
        ],
    )

    nlu = TFLiteNLU("tflite")
    dialogue_manager = DialogueManager()
    manager = TextToSpeechManager(
        TextToSpeechClient(KEY_ID, KEY_SECRET), PyAudioOutput(),
    )

    @pipeline.event
    def on_activate(context):
        print("active")

    @pipeline.event
    def on_recognize(context):
        pipeline.pause()
        results = nlu(context.transcript)
        response = dialogue_manager(results)
        if response:
            manager.synthesize(response, "text", "demo-male")
        pipeline.resume()

        if results.intent == "AMAZON.StopIntent":
            pipeline.stop()

    manager.synthesize(Response.WELCOME.value, "text", "demo-male")
    pipeline.start()
    pipeline.run()