GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • speechmatics.client
  • speechmatics.batch_client
  • speechmatics.exceptions
  • speechmatics.helpers
  • speechmatics.models
  • speechmatics.client
  • Speechmatics CLI Tool
  • Documentation overview

This view

  • Original page
  • New address

GeezerVison is showing speechmatics.github.io — speechmatics-python — speechmatics-python documentation

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

LANGUAGE = "en"
AUDIO_FILE_PATH = "/path/to/file"
CONNECTION_URL = f"wss://eu2.rt.speechmatics.com/v2/{LANGUAGE}"
AUTH_TOKEN = "add token here"

# Create a transcription client
ws = speechmatics.client.WebsocketClient(
    speechmatics.models.ConnectionSettings(
        url=CONNECTION_URL,
        auth_token=AUTH_TOKEN,
    )
)


# Define an event handler to print the partial transcript
def print_partial_transcript(msg):
    print(f"(PART) {msg['metadata']['transcript']}")


# Define an event handler to print the full transcript
def print_transcript(msg):
    print(f"(FULL) {msg['metadata']['transcript']}")


# Register the event handler for partial transcript
ws.add_event_handler(
    event_name=speechmatics.models.ServerMessageType.AddPartialTranscript,
    event_handler=print_partial_transcript,
)

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

settings = speechmatics.models.AudioSettings()

# Define transcription parameters
conf = speechmatics.models.TranscriptionConfig(
    language=LANGUAGE,
    enable_partials=True,
)

with open("example.wav", 'rb') as file:
    ws.run_synchronously(file, conf, settings)

Command-line usage¶

Please see the GitHub readme.

Reference¶

  • speechmatics.client
  • speechmatics.batch_client
  • speechmatics.exceptions
  • speechmatics.helpers
  • speechmatics.models
  • speechmatics.client
  • Speechmatics CLI Tool

Indices and tables¶

  • Index

  • Module Index

  • Search Page

©2024, Cantab Research Ltd.. | Powered by Sphinx 4.4.0 & Alabaster 0.7.12 | Page source
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.