/
mikopbx
/
ModuleSpeechRecognize
Обзор
Документация
Войти
/
mikopbx
/
ModuleSpeechRecognize
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
master
Lib/python/synthesize_stream.py
27 строк
963 B
boffart
init
02 окт 2025, 12:39
02 окт 2025, 12:39
107ee1d
Код
Авторство
О чём код?
#! /usr/bin/env python3 from audio import audio_open_write from auth import authorization_metadata from common import ( BaseSynthesisParser, make_channel, build_synthesis_request, ) from tinkoff.cloud.tts.v1 import tts_pb2_grpc, tts_pb2 def main(): args = BaseSynthesisParser().parse_args() if args.encoding == tts_pb2.LINEAR16 and args.rate != 48000: raise ValueError("LINEAR16 supports only 48kHz for now, use RAW_OPUS") with audio_open_write(args.output_file, args.encoding, args.rate) as audio_writer: stub = tts_pb2_grpc.TextToSpeechStub(make_channel(args)) request = build_synthesis_request(args) metadata = authorization_metadata(args.api_key, args.secret_key, "tinkoff.cloud.tts") responses = stub.StreamingSynthesize(request, metadata=metadata) for stream_response in responses: audio_writer.write(stream_response.audio_chunk) if __name__ == "__main__": main()