Python Tinkoff Speech API
Project description
Tinkoff Python Speech API examples
Usage
Install from PyPi
pip install tinkoff-voicekit-client
Common
Return 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:
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)
my_config = {
"encoding": "LINEAR16",
"sample_rate_hertz": 8000,
"num_channels": 1
}
# recognise method call
response = client.recognize("path/to/audio/file", my_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)
my_config = {
"encoding": "LINEAR16",
"sample_rate_hertz": 8000,
"num_channels": 1
}
stream_config = {"config": my_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:
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)
my_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", my_config)
# text
rows_responses = client.streaming_synthesize("Мой красивый текст", my_config)
# use it if you want get audio file results
# audio file
client.synthesize_to_audio_wav("path/to/file/with/text", my_config, "output/dir")
# text
client.synthesize_to_audio_wav("Мой красивый текст", my_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.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 808eed29d4b276d9df83cf91d637100f7b4484a8e46ee70942c2ee0a39b22769 |
|
MD5 | 6836a1f69f13ed5f500edad449a68387 |
|
BLAKE2b-256 | bd3f3912aae7747c2cf41aeec0f6334c615e8f5b4de3a10172cb5b17ed8a771d |
Close
Hashes for tinkoff_voicekit_client-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9baa551886f91fc450ee38995fcec0905b38a66f56fddd8b7dab56d759d82069 |
|
MD5 | 5cda6f1cdc906b2106e470b2eda04732 |
|
BLAKE2b-256 | 9f7420777f491bcc6611b7d3b1310c69e8173f5d8a96cd7fd7a422354dd12e9b |