Python client library and CLI for Speechmatics Realtime and Batch ASR v2 APIs.
-
Setting an auth token for CLI authentication:
speechmatics config set --auth-token $AUTH_TOKEN
Auth tokens are stored in toml config at HOME_DIR/.speechmatics/config.
You may also set the auth_token for each CLI command using the --auth-token flag.
The --auth-token flag overrides the value stored in the config file, e.g.
speechmatics transcribe --auth-token $AUTH_TOKEN example_audio.wav
-
Removing an auth_token from the toml file:
speechmatics config unset --auth-token
-
Setting URLs for connecting to transcribers. These values can be used in places of the --url flag:
speechmatics config set --rt-url wss://eu2.rt.speechmatics.com/v2 --batch-url https://asr.api.speechmatics.com/v2
-
Unsetting transcriber URLs in the toml config:
speechmatics config unset --rt-url --batch-url
-
Setting URLs for connecting to transcribers. These values can be used in places of the --url flag:
speechmatics config set --rt-url wss://eu2.rt.speechmatics.com/v2 --batch-url https://asr.api.speechmatics.com/v2
-
Unsetting transcriber URLs in the toml config:
speechmatics config unset --rt-url --batch-url
Realtime ASR
-
Starting a real-time session for self-service SaaS customers using a .wav file as the input audio:
speechmatics transcribe --lang en example_audio.wav
-
Real-time transcription of online stream (needs ffmpeg installed):
ffmpeg -v 0 -i https://cdn.bitmovin.com/content/assets/art-of-motion-dash-hls-progressive/mpds/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.mpd \
-f s16le -ar 44100 -ac 1 -acodec pcm_s16le - | \
speechmatics transcribe --raw pcm_s16le --sample-rate 44100 -
-
Starting a real-time session for enterprise SaaS customers using a .wav file as the input audio:
URL=wss://neu.rt.speechmatics.com/v2/en
speechmatics transcribe --url $URL example_audio.wav
-
Starting a real-time session for on-prem customers using a .wav file as the input audio:
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 using verbose output:
speechmatics -v transcribe --url $URL --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 --url $URL --ssl-mode none -
-
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 --url $URL --ssl-mode none --raw pcm_f32le --sample-rate 44100 -
-
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 --url $URL --ssl-mode none --enable-partials --raw pcm_f32le --sample-rate 44100 -
Add the --print-json
argument to see the raw JSON transcript messages being sent rather than just the plaintext transcript.
Batch ASR
-
Submit a .wav file for batch ASR processing
speechmatics batch transcribe --lang en example_audio.wav
-
Files may be submitted for asynchronous processing
speechmatics batch submit example_audio.wav
-
Enterprise SaaS and on-prem customers can point to a custom runtime:
URL=https://trial.asr.api.speechmatics.com/v2/
speechmatics batch transcribe --url $URL example_audio.wav
-
Check processing status of a job
speechmatics batch job-status --job-id $JOB_ID
-
Retrieve completed transcription
speechmatics batch get-results --job-id $JOB_ID
-
Submit a job with automatic language identification
speechmatics batch transcribe --language auto --langid-langs en,es example_audio.wav
If Speechmatics is not able to identify a language with high enough confidence, the job will be rejected. This is to reduce the risk of transcribing incorrectly.
--langid-langs
is optional and specifies what language(s) you expect to be detected in the source files.
-
Submit a job with translation
speechmatics batch transcribe --translation-langs de,es --output-format json-v2 example_audio.wav
--translation-langs
is supported in asynchronous mode as well, and translation output can be retrieved using get-results
with --output-format json-v2
set.
When combining language identification with translation, we can't know if the identified language can be translated
to your translation targets. If the translation pair is not supported, the error will be recorded in the metadata of the transcript.
-
Start a real-time transcription with translation session using microphone audio and pipe to transcriber
ffmpeg -loglevel quiet -f alsa -i hw:0 -f f32le -acodec pcm_f32le -ar 44100 - \
| speechmatics rt transcribe --url $URL --ssl-mode none --raw pcm_f32le --sample-rate 44100 \
--print-json --translation-langs fr -
-
Submit a job with summarization
speechmatics batch transcribe --summarize --output-format json-v2 example_audio.wav
-
Submit a job with sentiment analysis
speechmatics batch transcribe --sentiment-analysis --output-format json-v2 example_audio.wav
-
Submit a job with topic detection
speechmatics batch transcribe --detect-topics --output-format json-v2 example_audio.wav
-
Submit a job with auto chapters
speechmatics batch transcribe --detect-chapters --output-format json-v2 example_audio.wav
Custom Transcription Config File
-
Instead of passing all the transcription options via the command line you can also pass a transcription config file.
The config file is a JSON file that contains the transcription options.
The config file can be passed to the CLI using the --config-file
option.
speechmatics transcribe --config-file transcription_config.json example_audio.wav
-
The format of this JSON file is described in detail in the
Batch API documentation
and RT API documentation.
This package includes tooling for benchmarking transcription and diarization accuracy.
If you have any issues with this library or encounter any bugs then please get in touch with us at support@speechmatics.com.