Skip to main content

Python library and CLI for Speechmatics

Project description

speechmatics-python   Tests codecov License

Python client library and CLI for Speechmatics Realtime and Batch ASR v2 APIs.

Getting started

To install from PyPI:

$ pip install speechmatics-python

To install from source:

$ git clone https://github.com/speechmatics/speechmatics-python
$ cd speechmatics-python && python setup.py install

Requirements

  • Python 3.7+

Example command-line usage

Realtime ASR

  • A normal real time session using a .wav file as the input audio:

    # Point URL to the local instance of Speechmatics
    $ URL=ws://realtimeappliance.yourcompany:9000/v2
    
    $ speechmatics transcribe --url $URL --lang en --ssl-mode none example_audio.wav
    
  • Show the messages that are going over the websocket connection:

    $ speechmatics -v transcribe --url $URL --lang en --ssl-mode none example_audio.wav
    
  • The CLI also accepts an audio stream on standard input. Transcribe the piped input audio:

    $ cat example_audio.wav | speechmatics transcribe --ssl-mode none --url $URL --lang en -
    
  • Pipe audio directly from the microphone (example uses MacOS with ffmpeg)

    List available input devices:

    $ ffmpeg -f avfoundation -list_devices true -i ""
    

    There needs to be at least one available microphone attached to your computer. The command below gets the microphone input and pipes it to the transcriber. You may need to change the sample rate to match the sample rate that your machine records at. You may also need to replace :default with something like :0 or :1 if you want to use a specific microphone.

    $ ffmpeg -loglevel quiet -f avfoundation -i ":default" -f f32le -acodec pcm_f32le -ar 44100 - \
    >   | speechmatics transcribe --ssl-mode none --url $URL --raw pcm_f32le --sample-rate 44100 --lang en -
    
  • Transcribe in real-time with partials (example uses Ubuntu with ALSA). In this mode, the transcription engine produces words instantly, which may get updated as additional context becomes available.

    List available input devices:

    $ cat /proc/asound/cards
    

    Record microphone audio and pipe to transcriber:

    $ ffmpeg -loglevel quiet -f alsa -i hw:0 -f f32le -acodec pcm_f32le -ar 44100 - \
        | speechmatics transcribe --ssl-mode none --url $URL --enable-partials --raw pcm_f32le --sample-rate 44100 --lang en -
    

    Batch ASR

  • Submit a .wav file for batch ASR processing

    # Point URL to Speechmatics SaaS (Batch Virtual Appliance is also supported)
    $ URL=https://asr.api.speechmatics.com/v2/
    $ AUTH_TOKEN='abcd01234'
    
    $ speechmatics batch transcribe --url $URL --auth-token $AUTH_TOKEN --lang en example_audio.wav
    
  • Files may be submitted for asynchronous processing

    $ speechmatics batch submit --url $URL --auth-token $AUTH_TOKEN --lang en example_audio.wav
    
  • Check processing status of a job

    # $JOB_ID is from the submit command output
    $ speechmatics batch job-status --url $URL --auth-token $AUTH_TOKEN --job-id $JOB_ID
    
  • Retrieve completed transcription

    # $JOB_ID is from the submit command output
    $ speechmatics batch get-results --url $URL --auth-token $AUTH_TOKEN --job-id $JOB_ID
    

API documentation

Please see https://speechmatics.github.io/speechmatics-python/.

Testing

To install development dependencies and run tests

$ pip install -r requirements-dev.txt
$ make test

Support

If you have any issues with this library or encounter any bugs then please get in touch with us at support@speechmatics.com.


License: MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

speechmatics-python-1.2.2.tar.gz (36.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

speechmatics_python-1.2.2-py3-none-any.whl (24.6 kB view details)

Uploaded Python 3

File details

Details for the file speechmatics-python-1.2.2.tar.gz.

File metadata

  • Download URL: speechmatics-python-1.2.2.tar.gz
  • Upload date:
  • Size: 36.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for speechmatics-python-1.2.2.tar.gz
Algorithm Hash digest
SHA256 44e985c96c43f9e60c225c7b29526eb51371e120fca078021a8011b31d3c44ea
MD5 25cd8b36a37e633f40e4a5c942f4bb30
BLAKE2b-256 faa20d805ebd4138dd4556ab9310fc3a1d0fa82db4655fd0acd12e61d028993e

See more details on using hashes here.

File details

Details for the file speechmatics_python-1.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for speechmatics_python-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e41be20123b3e510ba00ed3aae6dd1d92ae4606a368a671a79a2b375d13fefc8
MD5 528d13782d57772a4af5ef1faa09c383
BLAKE2b-256 f64bd29b0e62f2d6fac5f6815de89e75a808e5979aa7b70e6b2b9d3e447330d4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page