speechmatics / speechmatics-python

Python library and CLI for Speechmatics
https://speechmatics.github.io/speechmatics-python/
MIT License
58 stars 14 forks source link

Speechmatics python library and cli fails with httpx.RemoteProtocolError #105

Closed praveen5733 closed 1 week ago

praveen5733 commented 1 week ago

Describe the bug using Speechmatics-python library to start a transcribe job fails with httpcore.RemoteProtocolError: <ConnectionTerminated error_code:0, last_stream_id:1, additional_data:None> The same error occurs using speechmatics CLI tool as well.

To Reproduce

system used : Apple M2 Pro, macOS Sonoma steps followed from python example in below link used exactly the same sample code provided https://docs.speechmatics.com/introduction/batch-guide#batch-transcription-examples Replace with API key and the path to audio file.

from speechmatics.batch_client import BatchClient
from httpx import HTTPStatusError

API_KEY = "YOUR_API_KEY"
PATH_TO_FILE = "example.wav"
LANGUAGE = "en"

settings = ConnectionSettings(
    url="https://asr.api.speechmatics.com/v2",
    auth_token=API_KEY,
)

# Define transcription parameters
conf = {
    "type": "transcription",
    "transcription_config": {
        "language": LANGUAGE
    }
}

# Open the client using a context manager
with BatchClient(settings) as client:
    try:
        job_id = client.submit_job(
            audio=PATH_TO_FILE,
            transcription_config=conf,
        )
        print(f'job {job_id} submitted successfully, waiting for transcript')

        # Note that in production, you should set up notifications instead of polling.
        # Notifications are described here: https://docs.speechmatics.com/features-other/notifications
        transcript = client.wait_for_completion(job_id, transcription_format='txt')
        # To see the full output, try setting transcription_format='json-v2'.
        print(transcript)
    except HTTPStatusError as e:
        if e.response.status_code == 401:
            print('Invalid API key - Check your API_KEY at the top of the code!')
        elif e.response.status_code == 400:
            print(e.response.json()['detail'])
        else:
            raise e

Is there a another way to use the speechmatics API ?