Giter VIP home page Giter VIP logo

voicekit_client_python's Introduction

Tinkoff Python VoiceKit API Library

Downloads Maintainability Build

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.

Documentation

Type schema

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
  • default
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)
  • change voice
from tinkoff_voicekit_client import ClientTTS

API_KEY = "api_key"
SECRET_KEY = "secret_key"

client = ClientTTS(API_KEY, SECRET_KEY)
config = {
        "audio_encoding": "RAW_OPUS",
        "sample_rate_hertz": 48000,
        "voice": {"name": "alyona"}
    }
client.synthesize_to_audio_wav("Приве! Меня зовут Алена.", config)

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"))

voicekit_client_python's People

Contributors

captainger avatar fsatka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

voicekit_client_python's Issues

Support aioboto3>=9.0.0

In version 9.0.0 aioboto3 package introduced a breaking change: aioboto3.client method no longer exists.

So, to support aioboto3>=9.0.0 we need to create aioboto3.Session() and then use session.client method.

ошибка при повторном исполь зовании метода longrunning_recognize_with_uploader

recognize_result, file_link = await self.__tinkoff_client.longrunning_recognize_with_uploader(
  File "/opt/iqtek/products/speech_analytic/dev/venv/3.8_backend/lib/python3.8/site-packages/tinkoff_voicekit_client/STT/aio_client_stt.py", line 141, in longrunning_recognize_with_uploader
    uri = await self._uploader.upload(source, object_name)
  File "/opt/iqtek/products/speech_analytic/dev/venv/3.8_backend/lib/python3.8/site-packages/tinkoff_voicekit_client/Uploader/aio_uploader.py", line 34, in upload
    async with self._s3 as client:
  File "/opt/iqtek/products/speech_analytic/dev/venv/3.8_backend/lib/python3.8/site-packages/aiobotocore/session.py", line 20, in __aenter__
    self._client = await self._coro
RuntimeError: cannot reuse already awaited coroutine

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.