speechmatics-python

speechmatics-python provides API wrapper and CLI to access the Speechmatics Realtime and Batch API v2.

Example library usage

The example below illustrates a waveform audio file being opened and transcribed with Realtime.

import speechmatics

# Define connection parameters
conn = speechmatics.models.ConnectionSettings(
    url="ws://localhost:9000/v2",
    ssl_context=None,
)

# Create a transcription client
ws = speechmatics.client.WebsocketClient(conn)

# Define transcription parameters
conf = speechmatics.models.TranscriptionConfig(
    language='en',
)

# Define an event handler to print the transcript
def print_transcript(msg):
    print(msg['metadata']['transcript'])

# Register the event handler
ws.add_event_handler(
    event_name=speechmatics.models.ServerMessageType.AddTranscript,
    event_handler=print_transcript,
)

# Open the audio file
f = open('sample.wav', 'rb')

# Initiate transcription
ws.run_synchronously(f, conf, speechmatics.models.AudioSettings())

Command-line usage

Please see the GitHub readme.

Reference

Indices and tables