Python Tinkoff Speech API
Project description
Tinkoff Python VoiceKit API Library
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
from tinkoff_voicekit_client import ClientSTT
API_KEY = "my_api_key"
SECRET_KEY = "my_secret_key"
client = ClientSTT(API_KEY, SECRET_KEY)
client.something_method.__doc__
Methods initialize using config (Python dict) which satisfies one of the next json schema.
Recogniton (STT)
Example of using STT
- recognize
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)
- streaming recognize
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)
- long running recognize with uploader
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
}
request = {
"config": audio_config,
"group": "group_name"
}
file_path = "path/to/file"
audio_name_for_storage = "pretty name"
# this method automatically upload audio to long running storage and return uri
print(client.longrunning_recognize_with_uploader(file_path, request, audio_name_for_storage))
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)
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")
# ssml. There are only tag <speak>
client.synthesize_to_audio_wav("<speak>Мой красивый текст</speak>", audio_config, "output/dir", ssml=True)
Example of using Operations
- get operation by id
from tinkoff_voicekit_client import ClientOperations
API_KEY = "my_api_key"
SECRET_KEY = "my_secret_key"
operations = ClientOperations(API_KEY, SECRET_KEY)
running_operation_id = "42"
print(operations.get_operation({"id": running_operation_id}))
- cancel operation by id
from tinkoff_voicekit_client import ClientOperations
API_KEY = "my_api_key"
SECRET_KEY = "my_secret_key"
operations = ClientOperations(API_KEY, SECRET_KEY)
operation_filter = {"exact_id": "31"}
# return empty dict on success
print(operations.cancel_operation(operation_filter))
Example of using Uploader
from tinkoff_voicekit_client import Uploader
API_KEY = "my_api_key"
SECRET_KEY = "my_secret_key"
uploader = Uploader(API_KEY, SECRET_KEY)
path = "path/to/file"
print(uploader.upload(path, "object_name"))
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.2.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c02beeee9ac7c11e810b75e1514b9245fef2f85f880014b0844cd312cfc0cef |
|
MD5 | ce2fefa3b67d221b591fa4005dfc2a83 |
|
BLAKE2b-256 | 647a9c6a775b43da19747f0caf51901a03e6cbba89bc5bc52cc2cc8ec32efcf0 |
Close
Hashes for tinkoff_voicekit_client-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 626a8c54d4a33eaddd91264b6b874c9306d53a87936184367ac3a2f44e2fe613 |
|
MD5 | ea273bda6646ee4173d2a4e5fc056437 |
|
BLAKE2b-256 | 43341ea458f599e7a4bbc9c137201bb3b27663d5ce48b47321f719e150533e18 |