Skip to main content

Transcription APIs encapsulation

Project description

Description

ftvstt is a France Télévisions python library which encapsulates multiple online speech-to-text APIs, in order to call them as easily as possible.

It currently supports :

  • Amazon Transcribe
  • Google Cloud speech-to-text
  • Vocapia Voxsigma
  • Bertin Mediaspeech

Quickstart

ftvstt is not currently available through pip, you have to download the package and import it directly : ftvstt is currently available through pip by running : pip install ftvstt. You should then be able to import the package :

import ftvstt

Usage

Example of transcription through the services:

Vocapia Voxsigma:

vocapiaTranscriber = ftvstt.Vocapia("https://rest1.vocapia.com:8093/voxsigma")
vocapiaTranscriber.authenticate("EXAMPLE_ID","EXAMPLE_PASS")
transcript = vocapiaTranscriber.transcribe("/path/to/file.wav")
vocapiaTranscriber.deauthenticate()

Bertin Mediaspeech:

bertinTranscriber = ftvstt.Bertin("https://demo02.mediaspeech.com:4433/api")
bertinTranscriber.authenticate("EXAMPLE_ID","EXAMPLE_PASS")
transcript = bertinTranscriber.transcribe("/path/to/file.wav")
bertinTranscriber.deauthenticate()

Amazon transcribe:

amazonTranscriber = ftvstt.Amazon("AMAZON_S3_BUCKET_NAME")
amazonTranscriber.authenticate("AMAZON_AWS_ID_KEY", "AMAZON_AWS_SECRET_KEY")
transcript = amazonTranscriber.transcribe("/path/to/file.wav")
amazonTranscriber.deauthenticate()

You can also authenticate directly with path to the credentials csv file:

amazonTranscriber.authenticate_with_file("/path/to/amazon/credentials.csv")

You need an amazon AWS S3 bucket besides Amazon AWS Transcribe in order to make transcriptions.

If your file is already on a S3 bucket, use instead:

transcript = amazonTranscriber.transcribe("https://url/to/s3/file.wav", s3file=True)

Google cloud speech-to-text:

googleTranscriber = ftvstt.Google()
googleTranscriber.authenticate("GOOGLE_CLIENT_EMAIL", "GOOGLE_PIVATE_KEY")
transcript = googleTranscriber.transcribe("/path/to/file.wav")
googleTranscriber.deauthenticate()

You can also authenticate directly with path to client service credentials json file with google.

googleTranscriber.authenticate_with_file("/path/to/google/credentials.json")

Custom vocabulary file

For every provider except Bertin, you can add a custom vocabulary file of probable words as shown :

googleTranscriber = ftvstt.Google()
googleTranscriber.authenticate_with_file("/path/to/google/credentials.json")
googleTranscriber.set_vocabulary_file("/path/to/vocabulary/file.txt")
transcript = googleTranscriber.transcribe("/path/to/file.wav")
googleTranscriber.deauthenticate()

The vocabulary file should be of the form:

word1
word2
word3
...

Results handling

Once a transcription is done, the transcribe function of a Transcriber returns a Transcript instance from ftvstt.transcripts sub-module.

A Transcript instance, as transcript in previous codes, has several useful attributes :

transcript.text: a string containing the textual transcript of the audio file.
transcript.words: a list of Word instances from ftvstt.transcripts sub-module, each one has a content (str), a startTime (float), an endTime (float), a speaker (Speaker instance from ftvstt.transcripts sub-module) (and can have a confidence (float) depending on the provider used) attribute.
transcript.speakers: a list of Speaker instances from ftvstt.transcripts sub-module, each one has an id (int), (and can have a gender (str : "M" or "F") depending on the provider used).
transcript.raw: a string containing the raw result of the transcription received from the provider, which type is transcript.rawType (str : "json" or "xml").

You can also dump the results in a normalised (the same format for any provider) json file:

transcript.dump_normalised_result("/output/path/to/normalized/result.json")

You can also load a transcript from a raw result file:

with open("/path/to/bertin/raw/result.xml") as file:
    raw = file.read()

transcript = ftvstt.Transcript(raw=raw, provider=ftvstt.Bertin)

Error handling

If an error has occured during transcription, a custom python Exception from the ftvstt.exceptions sub-module will be raised. The error will also be accessbile in the exception attribute of the transcript result, as you can see in this example:

googleTranscriber = ftvstt.Google()
googleTranscriber.authenticate("/path/to/google/credentials.json")
try:
    transcript = googleTranscriber.transcribe("/path/to/file.wav")
except:
    pass
raise transcript.exception
googleTranscriber.deauthenticate()

Testing

Coming soon...

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

ftvstt-2.0.0.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

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

ftvstt-2.0.0-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file ftvstt-2.0.0.tar.gz.

File metadata

  • Download URL: ftvstt-2.0.0.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for ftvstt-2.0.0.tar.gz
Algorithm Hash digest
SHA256 15299252f91a157c99b166f326d25f86d9cad1c71a76d86afe1f5f5657e7dd28
MD5 a787af59e6879b268cd6144c248f3f0c
BLAKE2b-256 7e8ed7b032770013589498d198b21f6a8febaa0e864bd41a3265042787a8dd79

See more details on using hashes here.

File details

Details for the file ftvstt-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: ftvstt-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for ftvstt-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3cdae82b9cc2a633d7dd82e6349546baf68561f2750d175488818b3285846a68
MD5 ebb9aa8f38007f18bbe8ca9aef461102
BLAKE2b-256 4e549c13bfeae999fcf49fabd98fb89cec37dabff0e37b7d7f093c7219ca7350

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