Ejemplo n.º 1
0
def test_end(_mock):
    client = CloudClient(socket_url="", key_id="", key_secret="")
    client.connect()
    client._socket.recv.side_effect = [
        json.dumps(
            {
                "error": None,
                "final": False,
                "hypotheses": [{"confidence": 0.5, "transcript": "this is a test"}],
                "status": "ok",
            }
        ),
        json.dumps(
            {
                "error": None,
                "final": True,
                "hypotheses": [{"confidence": 0.5, "transcript": "this is a test"}],
                "status": "ok",
            }
        ),
    ]

    client.initialize()
    client.end()
    client.receive()
    assert client.is_final
Ejemplo n.º 2
0
def test_send_audio(_mock):
    client = CloudClient(socket_url="", key_id="", key_secret="")
    frame = np.random.rand(160).astype(np.int16)

    with pytest.raises(ConnectionError):
        client.send(frame)

    with pytest.raises(ConnectionError):
        client.end()

    client.connect()
    client.end()

    for i in range(100):
        client.send(frame)
    client.end()