예제 #1
0
async def test_process_stt(auth_cloud_mock, aioclient_mock):
    """Test handling around stt."""
    auth_cloud_mock.voice_api_url = "https://test.local/api"
    voice_api = voice.Voice(auth_cloud_mock)

    aioclient_mock.get(
        "https://test.local/api/connection_details",
        json={
            "authorized_key": "test-key",
            "endpoint_stt": "stt-url",
            "endpoint_tts": "tts-url",
            "valid": f"{(voice.utcnow() + timedelta(minutes=9)).timestamp()}",
        },
    )

    aioclient_mock.post(
        "stt-url?language=en-US",
        json={
            "RecognitionStatus": "Success",
            "DisplayText": "My Text"
        },
    )
    result = await voice_api.process_stt(b"feet", "video=test", "en-US")

    assert result.success
    assert result.text == "My Text"
예제 #2
0
async def test_token_handling(auth_cloud_mock, aioclient_mock):
    """Test handling around token."""
    auth_cloud_mock.voice_api_url = "https://test.local/api"
    voice_api = voice.Voice(auth_cloud_mock)

    assert not voice_api._validate_token()

    aioclient_mock.get(
        "https://test.local/api/connection_details",
        json={
            "authorized_key": "test-key",
            "endpoint_stt": "stt-url",
            "endpoint_tts": "tts-url",
            "valid": f"{(voice.utcnow() + timedelta(minutes=9)).timestamp()}",
        },
    )

    await voice_api._update_token()
    assert voice_api._validate_token()

    assert voice_api._endpoint_stt == "stt-url"
    assert voice_api._endpoint_tts == "tts-url"
    assert voice_api._token == "test-key"
예제 #3
0
async def test_process_tts(auth_cloud_mock, aioclient_mock):
    """Test handling around tts."""
    auth_cloud_mock.voice_api_url = "https://test.local/api"
    voice_api = voice.Voice(auth_cloud_mock)

    aioclient_mock.get(
        "https://test.local/api/connection_details",
        json={
            "authorized_key": "test-key",
            "endpoint_stt": "stt-url",
            "endpoint_tts": "tts-url",
            "valid": f"{(voice.utcnow() + timedelta(minutes=9)).timestamp()}",
        },
    )

    aioclient_mock.post(
        "tts-url",
        content=b"My sound",
    )
    result = await voice_api.process_tts("Text for Saying", "en-US",
                                         voice.Gender.FEMALE)

    assert result == b"My sound"