Python Tinkoff Speech API
Project description
Tinkoff Python Speech API examples
Usage
Install from PyPi
pip install tinkoff-voicekit-client
Common
Before using you must have API_KEY and SECRET_KEY. You can get the keys by leaving a request on our website.
Examples of using VoiceKit client:
Call documentation for public methods
client.something_method.__doc__
Methods initialize using config (Python dict) which satisfies one of the next json schema.
Recogniton (STT)
Base types schema:
types_value_definitions = {
"StringArray": {
"type": "array",
"items": {
"type": "string",
}
},
"AudioEncoding": {
"type": "string",
"enum": ["LINEAR16", "ALAW", "MULAW", "LINEAR32F", "RAW_OPUS", "MPEG_AUDIO"]
},
"VoiceActivityDetectionConfig": {
"type": "object",
"properties": {
"min_speech_duration": {"type": "number"},
"max_speech_duration": {"type": "number"},
"silence_duration_threshold": {"type": "number"},
"silence_prob_threshold": {"type": "number"},
"aggressiveness": {"type": "number"},
}
},
"SpeechContext": {
"type": "object",
"properties": {
"phrases": {"$ref": "#definitions/StringArray"},
"words": {"$ref": "#definitions/StringArray"}
}
},
"InterimResultsConfig": {
"type": "object",
"properties": {
"enable_interim_results": {"type": "boolean"},
"interval": {"type": "number"}
}
}
}
Recognition config schema:
recognition_config_schema = {
"type": "object",
"definitions": definitions,
"properties": {
"encoding": {"$ref": "#/definitions/AudioEncoding"},
"sample_rate_hertz": {"type": "number"},
"language_code": {"type": "string"},
"max_alternatives": {"type": "number"},
"speech_contexts": {
"type": "array",
"items": {
"$ref": "#/definitions/SpeechContext"
}
},
"enable_automatic_punctuation": {"type": "boolean"},
"model": {"type": "string"},
"num_channels": {"type": "number"},
"do_not_perform_vad": {"type": "boolean"},
"vad_config": {"$ref": "#/definitions/VoiceActivityDetectionConfig"}
},
"required": [
"sample_rate_hertz",
"num_channels",
"encoding",
],
"additionalProperties": False
}
Streaming recognition config schema:
streaming_recognition_config_schema = {
"type": "object",
"definitions": definitions,
"properties": {
"config": recognition_config_schema,
"single_utterance": {"type": "boolean"},
"interim_results_config": {"$ref": "#/definitions/InterimResultsConfig"}
},
"additionalProperties": False
}
Example of using STT
from tinkoff_voicekit_client import ClientSTT
API_KEY = "my_api_key"
SECRET_KEY = "my_secret_key"
client = ClientSTT(API_KEY, SECRET_KEY)
audio_config = {
"encoding": "LINEAR16",
"sample_rate_hertz": 8000,
"num_channels": 1
}
# recognise method call
response = client.recognize("path/to/audio/file", audio_config)
print(response)
from tinkoff_voicekit_client import ClientSTT
API_KEY = "my_api_key"
SECRET_KEY = "my_secret_key"
client = ClientSTT(API_KEY, SECRET_KEY)
audio_config = {
"encoding": "LINEAR16",
"sample_rate_hertz": 8000,
"num_channels": 1
}
stream_config = {"config": audio_config}
# recognise stream method call
with open("path/to/audio/file", "rb") as source:
responses = client.streaming_recognize(source, stream_config)
for response in responses:
print(response)
Example of Voice Activity Detection configuration
vad = {}
vad["min_speech_duration"] = min_speech_duration
vad["max_speech_duration"] = max_speech_duration
vad["silence_duration_threshold"] = silence_duration_threshold
vad["silence_prob_threshold"] = silence_prob_threshold
vad["aggressiveness"] = aggressiveness
my_config = {}
my_config["vad"] = vad
Synthesize (TTS)
Base types schema:
types_value_definitions = {
"AudioEncoding": {
"type": "string",
"enum": ["LINEAR16", "ALAW", "MULAW", "LINEAR32F", "RAW_OPUS"]
},
"SynthesisInput": {
"type": "object",
"properties": {
"text": {"type": "string"}
}
}
}
Streaming synthesis schema:
streaming_synthesize_config_schema = {
"type": "object",
"definitions": definitions,
"properties": {
"audio_encoding": {"$ref": "#/definitions/AudioEncoding"},
"speaking_rate": {"type": "number"},
"sample_rate_hertz": {"type": "number"}
},
"required": [
"sample_rate_hertz",
"audio_encoding",
],
"additionalProperties": False
}
Example of input file:
Я жду вашего ответа. Вы готовы сделать перевод?
# Давайте уточним получателя. Как его зовут?
commented lines # will not be synthesis
Example of using TTS
from tinkoff_voicekit_client import ClientTTS
API_KEY = "api_key"
SECRET_KEY = "secret_key"
client = ClientTTS(API_KEY, SECRET_KEY)
audio_config = {
"audio_encoding": "LINEAR16",
"sample_rate_hertz": 48000
}
# use it if you want work with proto results
# audio file
rows_responses = client.streaming_synthesize("path/to/file/with/text", audio_config)
# text
rows_responses = client.streaming_synthesize("Мой красивый текст", audio_config)
# use it if you want get audio file results
# audio file
client.synthesize_to_audio_wav("path/to/file/with/text", audio_config, "output/dir")
# text
client.synthesize_to_audio_wav("Мой красивый текст", audio_config, "output/dir")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for tinkoff_voicekit_client-0.1.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b993204419bf7a593f25c2e3909697bd6ca531bd1b4de8c44b4f5d7c22b09ec0 |
|
MD5 | 19d599d1a40d0593f414def60d059461 |
|
BLAKE2b-256 | 92b81c1e9f41239358a1fb99d663fb920f113e658fd585d1852683ea5ee64c57 |
Close
Hashes for tinkoff_voicekit_client-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88e84511d7ab42f3649105ed1e6a6771cc7121f1f9fc630ee9c0825e538cc4e6 |
|
MD5 | 16f0ca6cd1eec9a7df1c76457bbb13d1 |
|
BLAKE2b-256 | 56bbe6427cb8cad65c8f855bac6f7fff8b244683a5807ec39481d36fbf36aff4 |