{"id":336769,"date":"2022-08-09T09:00:11","date_gmt":"2022-08-09T09:00:11","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=336769"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=336769","title":{"rendered":"<span>\u0423\u0447\u0438\u043c\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Yandex SpeechKit \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Python \u0437\u0430 5 \u043c\u0438\u043d\u0443\u0442<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0413\u043e\u0434 \u043d\u0430\u0437\u0430\u0434 \u0434\u043b\u044f \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043d\u0443\u0436\u0434 \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u043e\u0431\u0435\u0440\u0442\u043a\u0443 <a href=\"https:\/\/cloud.yandex.ru\/services\/speechkit\" rel=\"noopener noreferrer nofollow\">Yandex SpeechKit<\/a> \u043d\u0430 Python, \u043e\u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0438 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u0430\u044f, \u0447\u0442\u043e \u0433\u0440\u0435\u0445 \u043d\u0435 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f : )<\/p>\n<p>\u041a\u0441\u0442\u0430\u0442\u0438, \u0432\u043e\u0442 \u043e\u043d\u0430: <a href=\"https:\/\/github.com\/TikhonP\/yandex-speechkit-lib-python\" rel=\"noopener noreferrer nofollow\">Yandex SpeechKit Python SDK<\/a>!<\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0447\u0430\u0442\u044c \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u0442\u044c \u0438 \u0441\u0438\u043d\u0442\u0435\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0447\u044c \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f Python 3.6 \u0438\u043b\u0438 \u0432\u044b\u0448\u0435. \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u044c \u043c\u043e\u0436\u043d\u043e \u0438\u0437 <a href=\"https:\/\/pypi.org\" rel=\"noopener noreferrer nofollow\">PyPI<\/a>:<\/p>\n<pre><code class=\"bash\">pip install speechkit<\/code><\/pre>\n<h2>\u0420\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0441 \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u044e \u044f\u043d\u0434\u0435\u043a\u0441\u0430<\/h2>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434, \u0441\u0442\u043e\u0438\u0442 \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0430\u0440\u0443 \u0441\u043b\u043e\u0432 \u043f\u0440\u043e \u0442\u043e, \u043a\u0430\u043a \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430 Yandex Cloud. \u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c, \u0412\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0439\u0442\u0438 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c <a href=\"https:\/\/cloud.yandex.ru\/\" rel=\"noopener noreferrer nofollow\"><u>cloud.yandex.ru<\/u><\/a> c \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0430\u043a\u0430\u0443\u043d\u0442\u0430 \u044f\u043d\u0434\u0435\u043a\u0441\u0430 \u0438\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439. \u0417\u0430\u0442\u0435\u043c, \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043b\u0430\u0442\u0435\u0436\u043d\u044b\u0439 \u0430\u043a\u043a\u0430\u0443\u043d\u0442, \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u043e\u0432\u0430\u0432 \u043f\u0440\u043e\u0431\u043d\u044b\u0439 \u043f\u0435\u0440\u0438\u043e\u0434. \u0412 \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0447\u0442\u043e-\u0442\u043e \u0442\u0430\u043a\u043e\u0435:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/42e\/e21\/d2a\/42ee21d2a09fb48bfd304ac901e37185.png\" alt=\"\u0421\u0442\u0430\u0440\u0442\u043e\u0432\u0430\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f\" title=\"\u0421\u0442\u0430\u0440\u0442\u043e\u0432\u0430\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f\" width=\"2872\" height=\"1822\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/42e\/e21\/d2a\/42ee21d2a09fb48bfd304ac901e37185.png\"\/><figcaption>\u0421\u0442\u0430\u0440\u0442\u043e\u0432\u0430\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f<\/figcaption><\/figure>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430 \u043c\u043e\u0436\u043d\u043e \u0438\u0437 URL \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f:<\/p>\n<p><code>https:\/\/console.cloud.yandex.ru\/folders\/b1gd129pp9ha0vnvf5g7<\/code> , \u0433\u0434\u0435 <code>b1gd129pp9ha0vnvf5g7<\/code> \u2014 \u044d\u0442\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430. \u041e\u043d \u043d\u0430\u043c \u0441\u043a\u043e\u0440\u043e \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f. <\/p>\n<p>\u0414\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a <em>API SpeechKit<\/em> \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c <em>IAM-\u0442\u043e\u043a\u0435\u043d<\/em>, \u0412\u0430\u043c \u043e\u0431 \u044d\u0442\u043e\u043c \u0431\u0435\u0441\u043f\u043e\u043a\u043e\u0438\u0442\u044c\u0441\u044f \u043d\u0435 \u043d\u0443\u0436\u043d\u043e, \u044d\u0442\u043e \u0443\u0436\u0435 &#171;\u0432\u0448\u0438\u0442\u043e&#187; \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443, \u043d\u0443\u0436\u043d\u043e \u043b\u0438\u0448\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0435\u0441\u0441\u0438\u0438. \u041f\u0440\u043e\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c <em>IAM-\u0442\u043e\u043a\u0435\u043d<\/em> \u0438\u0437 <em>OAuth-\u0442\u043e\u043a\u0435\u043d\u0430<\/em>, \u0412\u0430\u0448\u0435\u0433\u043e \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \u043d\u0430 \u044f\u043d\u0434\u0435\u043a\u0441\u0435, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0439\u0434\u0438\u0442\u0435 \u043f\u043e\u00a0<a href=\"https:\/\/oauth.yandex.ru\/authorize?response_type=token&amp;client_id=1a6990aa636648e9b2ef855fa7bec2fb\" rel=\"noopener noreferrer nofollow\">\u0441\u0441\u044b\u043b\u043a\u0435<\/a>, \u043d\u0430\u0436\u043c\u0438\u0442\u0435\u00a0<strong>\u0420\u0430\u0437\u0440\u0435\u0448\u0438\u0442\u044c<\/strong>\u00a0\u0438 \u0441\u043a\u043e\u043f\u0438\u0440\u0443\u0439\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 <em>OAuth-\u0442\u043e\u043a\u0435\u043d<\/em>. \u0412 \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u043b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u043e <a href=\"https:\/\/yandex-speechkit-lib-python.readthedocs.io\/en\/latest\/auth.html#speechkit.auth.generate_jwt\" rel=\"noopener noreferrer nofollow\"><em>JWT-\u0442\u043e\u043a\u0435\u043d\u0443<\/em><\/a> \u0438\u043b\u0438 <a href=\"https:\/\/yandex-speechkit-lib-python.readthedocs.io\/en\/latest\/auth.html#speechkit.auth.get_api_key\" rel=\"noopener noreferrer nofollow\"><em>API-\u043a\u043b\u044e\u0447\u0443<\/em><\/a> \u0434\u043b\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u043e\u0433\u043e \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430.<\/p>\n<h2>\u0421\u0438\u043d\u0442\u0435\u0437 \u0440\u0435\u0447\u0438<\/h2>\n<p>\u0418\u0442\u0430\u043a, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0432\u0441\u0435, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043e\u0431\u0440\u0435\u043b\u0430 \u0433\u043e\u043b\u043e\u0441, \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043b\u0438\u0448\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u0447\u0435\u043a:<\/p>\n<pre><code class=\"python\">from speechkit import Session, SpeechSynthesis  oauth_token = \"AQAAAAAsHJkgAAhjwXshft5QgUuRkX0Wubhjlk\" catalog_id = \"b1gd129pp9ha0vnvf5g7\"  # \u042d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 `Session` \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0438\u0437 \u0440\u0430\u0437\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445  session = Session.from_yandex_passport_oauth_token(oauth_token, catalog_id)  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u044d\u043a\u0437\u0435\u043c\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 `SpeechSynthesis`, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u044f `session`, # \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0436\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0443\u0436\u043d\u044b\u0439 \u043d\u0430\u043c IAM-\u0442\u043e\u043a\u0435\u043d  # \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f API \u0440\u0435\u043a\u0432\u0438\u0437\u0438\u0442\u044b \u0434\u043b\u044f \u0432\u0445\u043e\u0434\u0430 synthesizeAudio = SpeechSynthesis(session)  # \u041c\u0435\u0442\u043e\u0434 `.synthesize()` \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0438\u043d\u0442\u0435\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0447\u044c \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0435\u0435 \u0432 \u0444\u0430\u0439\u043b synthesizeAudio.synthesize(     'out.wav', text='\u041f\u0440\u0438\u0432\u0435\u0442 \u043c\u0438\u0440!',     voice='oksana', format='lpcm', sampleRateHertz='16000' )  # `.synthesize_stream()` \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 `io.BytesIO()` \u0441 \u0430\u0443\u0434\u0438\u043e\u0444\u0430\u0439\u043b\u043e\u043c audio_data = synthesizeAudio.synthesize_stream( text='\u041f\u0440\u0438\u0432\u0435\u0442 \u043c\u0438\u0440, \u0441\u043d\u043e\u0432\u0430!',     voice='oksana', format='lpcm', sampleRateHertz='16000' )<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e! \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438 \u043f\u043e\u043b\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 <a href=\"https:\/\/cloud.yandex.ru\/docs\/speechkit\/tts\/request\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u044f\u043d\u0434\u0435\u043a\u0441\u0430<\/a> \u0438\u043b\u0438 \u0432 <a href=\"https:\/\/yandex-speechkit-lib-python.readthedocs.io\/en\/latest\/speechkit.html#speechkit.SpeechSynthesis\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438<\/a>. <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u044d\u0442\u043e\u0442 \u0430\u0443\u0434\u0438\u043e\u0444\u0430\u0439\u043b \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0438\u0433\u0440\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u043b\u0435\u0435\u0440\u0430 \u0438\u043b\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <a href=\"https:\/\/pypi.org\/project\/PyAudio\/\" rel=\"noopener noreferrer nofollow\">PyAudio<\/a>. \u041a\u0441\u0442\u0430\u0442\u0438, \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0440\u0430\u0437\u0443\u043c\u043d\u0435\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u0430 \u043d\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0438\u0445 \u0432 \u0444\u0430\u0439\u043b, \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">import pyaudio   def pyaudio_play_audio_function(audio_data, num_channels=1,                                  sample_rate=16000, chunk_size=4000) -> None:     \"\"\"     \u0412\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u0430\u0443\u0434\u0438\u043e \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 lpcm (WAV)          :param bytes audio_data: \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0441\u043f\u0438\u0447\u043a\u0438\u0442\u043e\u043c     :param integer num_channels: \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u0430\u043d\u0430\u043b\u043e\u0432, \u0441\u043f\u0438\u0447\u043a\u0438\u0442 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442          \u043c\u043e\u043d\u043e \u0434\u043e\u0440\u043e\u0436\u043a\u0443, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0442\u043e\u0438\u0442 \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 `1`     :param integer sample_rate: \u0447\u0430\u0441\u0442\u043e\u0442\u0430 \u0434\u0438\u0441\u043a\u0440\u0435\u0442\u0438\u0437\u0430\u0446\u0438\u0438, \u0442\u0430\u043a\u0430\u044f \u0436\u0435          \u043a\u0430\u043a\u0443\u044e \u0432\u044b \u0443\u043a\u0430\u0437\u0430\u043b\u0438 \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0435 sampleRateHertz     :param integer chunk_size: \u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u0435\u043c\u043f\u043b\u0430 \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f,          \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u0440\u0435\u0433\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0441\u043b\u0438 \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u043f\u043e\u0442\u0440\u0435\u0441\u043a\u0438\u0432\u0430\u043d\u0438\u0435     \"\"\"     p = pyaudio.PyAudio()     stream = p.open(         format=pyaudio.paInt16,         channels=num_channels,         rate=sample_rate,         output=True,         frames_per_buffer=chunk_size     )      try:         for i in range(0, len(audio_data), chunk_size):             stream.write(audio_data[i:i + chunk_size])     finally:         stream.stop_stream()         stream.close()         p.terminate()  sample_rate = 16000 # \u0447\u0430\u0441\u0442\u043e\u0442\u0430 \u0434\u0438\u0441\u043a\u0440\u0435\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043e\u043b\u0436\u043d\u0430                      # \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0442\u044c \u043f\u0440\u0438 \u0441\u0438\u043d\u0442\u0435\u0437\u0435 \u0438 \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0438 audio_data = synthesizeAudio.synthesize_stream(     text='\u041f\u0440\u0438\u0432\u0435\u0442 \u043c\u0438\u0440, \u0441\u043d\u043e\u0432\u0430 \u0438 \u0441\u043d\u043e\u0432\u0430!',     voice='oksana', format='lpcm', sampleRateHertz=sample_rate ) # \u0412\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c \u0441\u0438\u043d\u0442\u0435\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b pyaudio_play_audio_function(audio_data, sample_rate=sample_rate)<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u0433\u043e\u043b\u043e\u0441\u043e\u043c \u044f\u043d\u0434\u0435\u043a\u0441\u0430 \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u0440\u044f\u043c\u043e \u0438\u0437 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043a\u0440\u0443\u0447\u0438\u0432\u0430\u0442\u044c \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u043e\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a \u0447\u0430\u0439\u043d\u0438\u043a\u0443, \u043a\u043e\u0444\u0435\u0432\u0430\u0440\u043a\u0435, \u0443\u0442\u044e\u0433\u0443 \u0438 \u043f\u044b\u043b\u0435\u0441\u043e\u0441\u0443! <\/p>\n<h2>\u0420\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435 \u0440\u0435\u0447\u0438<\/h2>\n<p>\u042f\u043d\u0434\u0435\u043a\u0441 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0442\u0440\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u044f: \u043f\u043e\u0442\u043e\u043a\u043e\u0432\u043e\u0435 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435, \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435 \u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435. \u041e \u0442\u043e\u043c \u0447\u0435\u043c \u043e\u043d\u0438 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0438 \u0437\u0430\u0447\u0435\u043c \u043d\u0443\u0436\u043d\u044b \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043d\u0430 <a href=\"https:\/\/cloud.yandex.ru\/docs\/speechkit\/stt\/\" rel=\"noopener noreferrer nofollow\">\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043a\u0435<\/a>. <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u043a\u0440\u0430\u0442\u0446\u0435, <strong>\u043f\u043e\u0442\u043e\u043a\u043e\u0432\u043e\u0435 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435<\/strong> \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u043f\u0440\u044f\u043c\u043e \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0438 \u0441\u0442\u0440\u0438\u043c\u0438\u043d\u0433\u0430 \u0430\u0443\u0434\u0438\u043e, \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043d\u0430 \u043b\u0435\u0442\u0443. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443\u043c\u043d\u0430\u044f \u043a\u043e\u043b\u043e\u043d\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u0447\u0430\u0442\u044c \u0437\u0430\u0434\u0443\u043c\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u043a \u0435\u0439 \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f, \u043a\u0430\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0435\u0449\u0435 \u043d\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b \u0444\u0440\u0430\u0437\u0443. \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u0442\u043e\u043a\u043e\u0432\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u044f \u0432 <a href=\"https:\/\/github.com\/TikhonP\/yandex-speechkit-lib-python\/blob\/master\/examples\/streaming_recognize.py\" rel=\"noopener noreferrer nofollow\">\u0433\u0438\u0442\u0445\u0430\u0431\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438<\/a>, \u0435\u0449\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432 <a href=\"https:\/\/yandex-speechkit-lib-python.readthedocs.io\/en\/latest\/speechkit.html#speechkit.DataStreamingRecognition\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>. <\/p>\n<p><strong>\u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435<\/strong> \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 \u0432 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u043e\u0447\u0435\u043d\u044c \u0434\u043b\u0438\u043d\u043d\u044b\u0445 \u0430\u0443\u0434\u0438\u043e\u0437\u0430\u043f\u0438\u0441\u0435\u0439, \u043e\u043d\u043e \u0434\u0435\u0448\u0435\u0432\u043b\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043d\u043e \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u043e\u0436\u0434\u0430\u0442\u044c. \u0412\u043e\u0442 <a href=\"https:\/\/github.com\/TikhonP\/yandex-speechkit-lib-python\/blob\/master\/examples\/long_audio_recognition.py\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/a> \u0438 <a href=\"https:\/\/yandex-speechkit-lib-python.readthedocs.io\/en\/latest\/speechkit.html#speechkit.RecognitionLongAudio\" rel=\"noopener noreferrer nofollow\">\u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430<\/a>. <\/p>\n<p>\u041c\u044b \u0436\u0435 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u2014 <strong>\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435. <\/strong>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u043f\u0438\u0448\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432 \u0444\u0430\u0439\u043b \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 WAV. <\/p>\n<pre><code class=\"python\">from speechkit import ShortAudioRecognition   # \u0427\u0438\u0442\u0430\u0435\u043c \u0444\u0430\u0439\u043b with open('voice.wav', 'rb') as f:     data = f.read()      # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e `session` \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u043d\u0435\u0435 recognizeShortAudio = ShortAudioRecognition(session)  # \u041f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b \u0438 \u0435\u0433\u043e \u0444\u043e\u0440\u043c\u0430\u0442 \u0432 \u043c\u0435\u0442\u043e\u0434 `.recognize()`,  # \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u0441 \u0442\u0435\u043a\u0441\u0442\u043e\u043c text = recognizeShortAudio.recognize( data, format='lpcm', sampleRateHertz='48000') print(text)<\/code><\/pre>\n<p>\u0423\u0440\u0430! \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043a\u0440\u0443\u0442\u0438\u0442\u044c \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u044b\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043a \u0447\u0435\u043c\u0443 \u0443\u0433\u043e\u0434\u043d\u043e. <a href=\"https:\/\/yandex-speechkit-lib-python.readthedocs.io\/en\/latest\/speechkit.html#speechkit.ShortAudioRecognition\" rel=\"noopener noreferrer nofollow\">\u0412\u043e\u0442 \u0441\u0441\u044b\u043b\u043a\u0430<\/a> \u043d\u0430 \u043f\u043e\u043b\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430, \u0435\u0441\u043b\u0438 \u0412\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435, \u043e\u0442\u043b\u0438\u0447\u043d\u043e\u043c \u043e\u0442 WAV, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440. <\/p>\n<p>\u041d\u0430\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u043a \u043f\u043e\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <em>PyAudio<\/em> \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0433\u043e\u043b\u043e\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0442\u043e\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 \u0441\u043f\u0438\u0447\u043a\u0438\u0442 \u0434\u043b\u044f \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"python\">import io import wave import pyaudio   def record_audio(seconds, sample_rate,                   chunk_size=4000, num_channels=1) -> bytes:     \"\"\"     \u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0430\u0443\u0434\u0438\u043e \u0434\u0430\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438          :param integer seconds: \u0412\u0440\u0435\u043c\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445     :param integer sample_rate: \u0447\u0430\u0441\u0442\u043e\u0442\u0430 \u0434\u0438\u0441\u043a\u0440\u0435\u0442\u0438\u0437\u0430\u0446\u0438\u0438, \u0442\u0430\u043a\u0430\u044f \u0436\u0435          \u043a\u0430\u043a\u0443\u044e \u0432\u044b \u0443\u043a\u0430\u0437\u0430\u043b\u0438 \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0435 sampleRateHertz     :param integer chunk_size: \u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u0435\u043c\u043f\u043b\u0430 \u0437\u0430\u043f\u0438\u0441\u0438     :param integer num_channels: \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u0430\u043d\u0430\u043b\u043e\u0432, \u0432 \u0440\u0435\u0436\u0438\u043c\u0435\u0440 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e         \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u044f \u0441\u043f\u0438\u0447\u043a\u0438\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043c\u043e\u043d\u043e \u0434\u043e\u0440\u043e\u0436\u043a\u0443,          \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0442\u043e\u0438\u0442 \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 `1`     :return: \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 BytesIO \u0441 \u0430\u0443\u0434\u0438\u043e \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 WAV     :rtype: bytes     \"\"\"      p = pyaudio.PyAudio()     stream = p.open(         format=pyaudio.paInt16,         channels=num_channels,         rate=sample_rate,         input=True,         frames_per_buffer=chunk_size     )     frames = []     try:         for i in range(0, int(sample_rate \/ chunk_size * seconds)):             data = stream.read(chunk_size)             frames.append(data)     finally:         stream.stop_stream()         stream.close()         p.terminate()              container = io.BytesIO()     wf = wave.open(container, 'wb')     wf.setnchannels(num_channels)     wf.setsampwidth(p.get_sample_size(pyaudio.paInt16))     wf.setframerate(sample_rate)     wf.writeframes(b''.join(frames))     container.seek(0)     return container  sample_rate = 16000 # \u0447\u0430\u0441\u0442\u043e\u0442\u0430 \u0434\u0438\u0441\u043a\u0440\u0435\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043e\u043b\u0436\u043d\u0430                      # \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0442\u044c \u043f\u0440\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0438 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0438      # \u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0430\u0443\u0434\u0438\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e 3 \u0441\u0435\u043a\u0443\u043d\u0434\u044b data = record_audio(3, sample_rate)  # \u041e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0430 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435 text = recognizeShortAudio.recognize(     data, format='lpcm', sampleRateHertz=sample_rate) print(text)<\/code><\/pre>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0435. \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0432\u0430\u043c \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u043b\u0430\u0441\u044c <a href=\"https:\/\/github.com\/TikhonP\/yandex-speechkit-lib-python\" rel=\"noopener noreferrer nofollow\">\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430<\/a> : ) \u0411\u0443\u0434\u0443 \u0440\u0430\u0434 \u043f\u0443\u043b-\u0440\u0435\u043a\u0432\u0435\u0441\u0442\u0430\u043c!<\/p>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435!<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/681566\/\"> https:\/\/habr.com\/ru\/post\/681566\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0413\u043e\u0434 \u043d\u0430\u0437\u0430\u0434 \u0434\u043b\u044f \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043d\u0443\u0436\u0434 \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u043e\u0431\u0435\u0440\u0442\u043a\u0443 <a href=\"https:\/\/cloud.yandex.ru\/services\/speechkit\" rel=\"noopener noreferrer nofollow\">Yandex SpeechKit<\/a> \u043d\u0430 Python, \u043e\u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0438 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u0430\u044f, \u0447\u0442\u043e \u0433\u0440\u0435\u0445 \u043d\u0435 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f : )<\/p>\n<p>\u041a\u0441\u0442\u0430\u0442\u0438, \u0432\u043e\u0442 \u043e\u043d\u0430: <a href=\"https:\/\/github.com\/TikhonP\/yandex-speechkit-lib-python\" rel=\"noopener noreferrer nofollow\">Yandex SpeechKit Python SDK<\/a>!<\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0447\u0430\u0442\u044c \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u0442\u044c \u0438 \u0441\u0438\u043d\u0442\u0435\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0447\u044c \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f Python 3.6 \u0438\u043b\u0438 \u0432\u044b\u0448\u0435. \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u044c \u043c\u043e\u0436\u043d\u043e \u0438\u0437 <a href=\"https:\/\/pypi.org\" rel=\"noopener noreferrer nofollow\">PyPI<\/a>:<\/p>\n<pre><code class=\"bash\">pip install speechkit<\/code><\/pre>\n<h2>\u0420\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0441 \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u044e \u044f\u043d\u0434\u0435\u043a\u0441\u0430<\/h2>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434, \u0441\u0442\u043e\u0438\u0442 \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0430\u0440\u0443 \u0441\u043b\u043e\u0432 \u043f\u0440\u043e \u0442\u043e, \u043a\u0430\u043a \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430 Yandex Cloud. \u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c, \u0412\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0439\u0442\u0438 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c <a href=\"https:\/\/cloud.yandex.ru\/\" rel=\"noopener noreferrer nofollow\"><u>cloud.yandex.ru<\/u><\/a> c \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0430\u043a\u0430\u0443\u043d\u0442\u0430 \u044f\u043d\u0434\u0435\u043a\u0441\u0430 \u0438\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439. \u0417\u0430\u0442\u0435\u043c, \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043b\u0430\u0442\u0435\u0436\u043d\u044b\u0439 \u0430\u043a\u043a\u0430\u0443\u043d\u0442, \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u043e\u0432\u0430\u0432 \u043f\u0440\u043e\u0431\u043d\u044b\u0439 \u043f\u0435\u0440\u0438\u043e\u0434. \u0412 \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0447\u0442\u043e-\u0442\u043e \u0442\u0430\u043a\u043e\u0435:<\/p>\n<figure class=\"full-width\"><figcaption>\u0421\u0442\u0430\u0440\u0442\u043e\u0432\u0430\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f<\/figcaption><\/figure>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430 \u043c\u043e\u0436\u043d\u043e \u0438\u0437 URL \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f:<\/p>\n<p><code>https:\/\/console.cloud.yandex.ru\/folders\/b1gd129pp9ha0vnvf5g7<\/code> , \u0433\u0434\u0435 <code>b1gd129pp9ha0vnvf5g7<\/code> \u2014 \u044d\u0442\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430. \u041e\u043d \u043d\u0430\u043c \u0441\u043a\u043e\u0440\u043e \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f. <\/p>\n<p>\u0414\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a <em>API SpeechKit<\/em> \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c <em>IAM-\u0442\u043e\u043a\u0435\u043d<\/em>, \u0412\u0430\u043c \u043e\u0431 \u044d\u0442\u043e\u043c \u0431\u0435\u0441\u043f\u043e\u043a\u043e\u0438\u0442\u044c\u0441\u044f \u043d\u0435 \u043d\u0443\u0436\u043d\u043e, \u044d\u0442\u043e \u0443\u0436\u0435 &#171;\u0432\u0448\u0438\u0442\u043e&#187; \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443, \u043d\u0443\u0436\u043d\u043e \u043b\u0438\u0448\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0435\u0441\u0441\u0438\u0438. \u041f\u0440\u043e\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c <em>IAM-\u0442\u043e\u043a\u0435\u043d<\/em> \u0438\u0437 <em>OAuth-\u0442\u043e\u043a\u0435\u043d\u0430<\/em>, \u0412\u0430\u0448\u0435\u0433\u043e \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \u043d\u0430 \u044f\u043d\u0434\u0435\u043a\u0441\u0435, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0439\u0434\u0438\u0442\u0435 \u043f\u043e\u00a0<a href=\"https:\/\/oauth.yandex.ru\/authorize?response_type=token&amp;client_id=1a6990aa636648e9b2ef855fa7bec2fb\" rel=\"noopener noreferrer nofollow\">\u0441\u0441\u044b\u043b\u043a\u0435<\/a>, \u043d\u0430\u0436\u043c\u0438\u0442\u0435\u00a0<strong>\u0420\u0430\u0437\u0440\u0435\u0448\u0438\u0442\u044c<\/strong>\u00a0\u0438 \u0441\u043a\u043e\u043f\u0438\u0440\u0443\u0439\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 <em>OAuth-\u0442\u043e\u043a\u0435\u043d<\/em>. \u0412 \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u043b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u043e <a href=\"https:\/\/yandex-speechkit-lib-python.readthedocs.io\/en\/latest\/auth.html#speechkit.auth.generate_jwt\" rel=\"noopener noreferrer nofollow\"><em>JWT-\u0442\u043e\u043a\u0435\u043d\u0443<\/em><\/a> \u0438\u043b\u0438 <a href=\"https:\/\/yandex-speechkit-lib-python.readthedocs.io\/en\/latest\/auth.html#speechkit.auth.get_api_key\" rel=\"noopener noreferrer nofollow\"><em>API-\u043a\u043b\u044e\u0447\u0443<\/em><\/a> \u0434\u043b\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u043e\u0433\u043e \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430.<\/p>\n<h2>\u0421\u0438\u043d\u0442\u0435\u0437 \u0440\u0435\u0447\u0438<\/h2>\n<p>\u0418\u0442\u0430\u043a, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0432\u0441\u0435, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043e\u0431\u0440\u0435\u043b\u0430 \u0433\u043e\u043b\u043e\u0441, \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043b\u0438\u0448\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u0447\u0435\u043a:<\/p>\n<pre><code class=\"python\">from speechkit import Session, SpeechSynthesis  oauth_token = \"AQAAAAAsHJkgAAhjwXshft5QgUuRkX0Wubhjlk\" catalog_id = \"b1gd129pp9ha0vnvf5g7\"  # \u042d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 `Session` \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0438\u0437 \u0440\u0430\u0437\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445  session = Session.from_yandex_passport_oauth_token(oauth_token, catalog_id)  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u044d\u043a\u0437\u0435\u043c\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 `SpeechSynthesis`, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u044f `session`, # \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0436\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0443\u0436\u043d\u044b\u0439 \u043d\u0430\u043c IAM-\u0442\u043e\u043a\u0435\u043d  # \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f API \u0440\u0435\u043a\u0432\u0438\u0437\u0438\u0442\u044b \u0434\u043b\u044f \u0432\u0445\u043e\u0434\u0430 synthesizeAudio = SpeechSynthesis(session)  # \u041c\u0435\u0442\u043e\u0434 `.synthesize()` \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0438\u043d\u0442\u0435\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0447\u044c \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0435\u0435 \u0432 \u0444\u0430\u0439\u043b synthesizeAudio.synthesize(     'out.wav', text='\u041f\u0440\u0438\u0432\u0435\u0442 \u043c\u0438\u0440!',     voice='oksana', format='lpcm', sampleRateHertz='16000' )  # `.synthesize_stream()` \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 `io.BytesIO()` \u0441 \u0430\u0443\u0434\u0438\u043e\u0444\u0430\u0439\u043b\u043e\u043c audio_data = synthesizeAudio.synthesize_stream( text='\u041f\u0440\u0438\u0432\u0435\u0442 \u043c\u0438\u0440, \u0441\u043d\u043e\u0432\u0430!',     voice='oksana', format='lpcm', sampleRateHertz='16000' )<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e! \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438 \u043f\u043e\u043b\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 <a href=\"https:\/\/cloud.yandex.ru\/docs\/speechkit\/tts\/request\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u044f\u043d\u0434\u0435\u043a\u0441\u0430<\/a> \u0438\u043b\u0438 \u0432 <a href=\"https:\/\/yandex-speechkit-lib-python.readthedocs.io\/en\/latest\/speechkit.html#speechkit.SpeechSynthesis\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438<\/a>. <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u044d\u0442\u043e\u0442 \u0430\u0443\u0434\u0438\u043e\u0444\u0430\u0439\u043b \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0438\u0433\u0440\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u043b\u0435\u0435\u0440\u0430 \u0438\u043b\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <a href=\"https:\/\/pypi.org\/project\/PyAudio\/\" rel=\"noopener noreferrer nofollow\">PyAudio<\/a>. \u041a\u0441\u0442\u0430\u0442\u0438, \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0440\u0430\u0437\u0443\u043c\u043d\u0435\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u0430 \u043d\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0438\u0445 \u0432 \u0444\u0430\u0439\u043b, \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">import pyaudio   def pyaudio_play_audio_function(audio_data, num_channels=1,                                  sample_rate=16000, chunk_size=4000) -> None:     \"\"\"     \u0412\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u0430\u0443\u0434\u0438\u043e \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 lpcm (WAV)          :param bytes audio_data: \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0441\u043f\u0438\u0447\u043a\u0438\u0442\u043e\u043c     :param integer num_channels: \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u0430\u043d\u0430\u043b\u043e\u0432, \u0441\u043f\u0438\u0447\u043a\u0438\u0442 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442          \u043c\u043e\u043d\u043e \u0434\u043e\u0440\u043e\u0436\u043a\u0443, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0442\u043e\u0438\u0442 \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 `1`     :param integer sample_rate: \u0447\u0430\u0441\u0442\u043e\u0442\u0430 \u0434\u0438\u0441\u043a\u0440\u0435\u0442\u0438\u0437\u0430\u0446\u0438\u0438, \u0442\u0430\u043a\u0430\u044f \u0436\u0435          \u043a\u0430\u043a\u0443\u044e \u0432\u044b \u0443\u043a\u0430\u0437\u0430\u043b\u0438 \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0435 sampleRateHertz     :param integer chunk_size: \u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u0435\u043c\u043f\u043b\u0430 \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f,          \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u0440\u0435\u0433\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0441\u043b\u0438 \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u043f\u043e\u0442\u0440\u0435\u0441\u043a\u0438\u0432\u0430\u043d\u0438\u0435     \"\"\"     p = pyaudio.PyAudio()     stream = p.open(         format=pyaudio.paInt16,         channels=num_channels,         rate=sample_rate,         output=True,         frames_per_buffer=chunk_size     )      try:         for i in range(0, len(audio_data), chunk_size):             stream.write(audio_data[i:i + chunk_size])     finally:         stream.stop_stream()         stream.close()         p.terminate()  sample_rate = 16000 # \u0447\u0430\u0441\u0442\u043e\u0442\u0430 \u0434\u0438\u0441\u043a\u0440\u0435\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043e\u043b\u0436\u043d\u0430                      # \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0442\u044c \u043f\u0440\u0438 \u0441\u0438\u043d\u0442\u0435\u0437\u0435 \u0438 \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0438 audio_data = synthesizeAudio.synthesize_stream(     text='\u041f\u0440\u0438\u0432\u0435\u0442 \u043c\u0438\u0440, \u0441\u043d\u043e\u0432\u0430 \u0438 \u0441\u043d\u043e\u0432\u0430!',     voice='oksana', format='lpcm', sampleRateHertz=sample_rate ) # \u0412\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c \u0441\u0438\u043d\u0442\u0435\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b pyaudio_play_audio_function(audio_data, sample_rate=sample_rate)<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u0433\u043e\u043b\u043e\u0441\u043e\u043c \u044f\u043d\u0434\u0435\u043a\u0441\u0430 \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u0440\u044f\u043c\u043e \u0438\u0437 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043a\u0440\u0443\u0447\u0438\u0432\u0430\u0442\u044c \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u043e\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a \u0447\u0430\u0439\u043d\u0438\u043a\u0443, \u043a\u043e\u0444\u0435\u0432\u0430\u0440\u043a\u0435, \u0443\u0442\u044e\u0433\u0443 \u0438 \u043f\u044b\u043b\u0435\u0441\u043e\u0441\u0443! <\/p>\n<h2>\u0420\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435 \u0440\u0435\u0447\u0438<\/h2>\n<p>\u042f\u043d\u0434\u0435\u043a\u0441 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0442\u0440\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u044f: \u043f\u043e\u0442\u043e\u043a\u043e\u0432\u043e\u0435 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435, \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435 \u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435. \u041e \u0442\u043e\u043c \u0447\u0435\u043c \u043e\u043d\u0438 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0438 \u0437\u0430\u0447\u0435\u043c \u043d\u0443\u0436\u043d\u044b \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043d\u0430 <a href=\"https:\/\/cloud.yandex.ru\/docs\/speechkit\/stt\/\" rel=\"noopener noreferrer nofollow\">\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043a\u0435<\/a>. <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u043a\u0440\u0430\u0442\u0446\u0435, <strong>\u043f\u043e\u0442\u043e\u043a\u043e\u0432\u043e\u0435 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435<\/strong> \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u043f\u0440\u044f\u043c\u043e \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0438 \u0441\u0442\u0440\u0438\u043c\u0438\u043d\u0433\u0430 \u0430\u0443\u0434\u0438\u043e, \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043d\u0430 \u043b\u0435\u0442\u0443. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443\u043c\u043d\u0430\u044f \u043a\u043e\u043b\u043e\u043d\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u0447\u0430\u0442\u044c \u0437\u0430\u0434\u0443\u043c\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u043a \u0435\u0439 \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f, \u043a\u0430\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0435\u0449\u0435 \u043d\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b \u0444\u0440\u0430\u0437\u0443. \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u0442\u043e\u043a\u043e\u0432\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u044f \u0432 <a href=\"https:\/\/github.com\/TikhonP\/yandex-speechkit-lib-python\/blob\/master\/examples\/streaming_recognize.py\" rel=\"noopener noreferrer nofollow\">\u0433\u0438\u0442\u0445\u0430\u0431\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438<\/a>, \u0435\u0449\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432 <a href=\"https:\/\/yandex-speechkit-lib-python.readthedocs.io\/en\/latest\/speechkit.html#speechkit.DataStreamingRecognition\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>. <\/p>\n<p><strong>\u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435<\/strong> \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 \u0432 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u043e\u0447\u0435\u043d\u044c \u0434\u043b\u0438\u043d\u043d\u044b\u0445 \u0430\u0443\u0434\u0438\u043e\u0437\u0430\u043f\u0438\u0441\u0435\u0439, \u043e\u043d\u043e \u0434\u0435\u0448\u0435\u0432\u043b\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043d\u043e \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u043e\u0436\u0434\u0430\u0442\u044c. \u0412\u043e\u0442 <a href=\"https:\/\/github.com\/TikhonP\/yandex-speechkit-lib-python\/blob\/master\/examples\/long_audio_recognition.py\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/a> \u0438 <a href=\"https:\/\/yandex-speechkit-lib-python.readthedocs.io\/en\/latest\/speechkit.html#speechkit.RecognitionLongAudio\" rel=\"noopener noreferrer nofollow\">\u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430<\/a>. <\/p>\n<p>\u041c\u044b \u0436\u0435 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u2014 <strong>\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435. <\/strong>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u043f\u0438\u0448\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432 \u0444\u0430\u0439\u043b \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 WAV. <\/p>\n<pre><code class=\"python\">from speechkit import ShortAudioRecognition   # \u0427\u0438\u0442\u0430\u0435\u043c \u0444\u0430\u0439\u043b with open('voice.wav', 'rb') as f:     data = f.read()      # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e `session` \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u043d\u0435\u0435 recognizeShortAudio = ShortAudioRecognition(session)  # \u041f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b \u0438 \u0435\u0433\u043e \u0444\u043e\u0440\u043c\u0430\u0442 \u0432 \u043c\u0435\u0442\u043e\u0434 `.recognize()`,  # \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u0441 \u0442\u0435\u043a\u0441\u0442\u043e\u043c text = recognizeShortAudio.recognize( data, format='lpcm', sampleRateHertz='48000') print(text)<\/code><\/pre>\n<p>\u0423\u0440\u0430! \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043a\u0440\u0443\u0442\u0438\u0442\u044c \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u044b\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043a \u0447\u0435\u043c\u0443 \u0443\u0433\u043e\u0434\u043d\u043e. <a href=\"https:\/\/yandex-speechkit-lib-python.readthedocs.io\/en\/latest\/speechkit.html#speechkit.ShortAudioRecognition\" rel=\"noopener noreferrer nofollow\">\u0412\u043e\u0442 \u0441\u0441\u044b\u043b\u043a\u0430<\/a> \u043d\u0430 \u043f\u043e\u043b\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430, \u0435\u0441\u043b\u0438 \u0412\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435, \u043e\u0442\u043b\u0438\u0447\u043d\u043e\u043c \u043e\u0442 WAV, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440. <\/p>\n<p>\u041d\u0430\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u043a \u043f\u043e\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <em>PyAudio<\/em> \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0433\u043e\u043b\u043e\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0442\u043e\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 \u0441\u043f\u0438\u0447\u043a\u0438\u0442 \u0434\u043b\u044f \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"python\">import io import wave import pyaudio   def record_audio(seconds, sample_rate,                   chunk_size=4000, num_channels=1) -> bytes:     \"\"\"     \u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0430\u0443\u0434\u0438\u043e \u0434\u0430\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438          :param integer seconds: \u0412\u0440\u0435\u043c\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445     :param integer sample_rate: \u0447\u0430\u0441\u0442\u043e\u0442\u0430 \u0434\u0438\u0441\u043a\u0440\u0435\u0442\u0438\u0437\u0430\u0446\u0438\u0438, \u0442\u0430\u043a\u0430\u044f \u0436\u0435          \u043a\u0430\u043a\u0443\u044e \u0432\u044b \u0443\u043a\u0430\u0437\u0430\u043b\u0438 \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0435 sampleRateHertz     :param integer chunk_size: \u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u0435\u043c\u043f\u043b\u0430 \u0437\u0430\u043f\u0438\u0441\u0438     :param integer num_channels: \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u0430\u043d\u0430\u043b\u043e\u0432, \u0432 \u0440\u0435\u0436\u0438\u043c\u0435\u0440 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e         \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u044f \u0441\u043f\u0438\u0447\u043a\u0438\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043c\u043e\u043d\u043e \u0434\u043e\u0440\u043e\u0436\u043a\u0443,          \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0442\u043e\u0438\u0442 \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 `1`     :return: \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 BytesIO \u0441 \u0430\u0443\u0434\u0438\u043e \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 WAV     :rtype: bytes     \"\"\"      p = pyaudio.PyAudio()     stream = p.open(         format=pyaudio.paInt16,         channels=num_channels,         rate=sample_rate,         input=True,         frames_per_buffer=chunk_size     )     frames = []     try:         for i in range(0, int(sample_rate \/ chunk_size * seconds)):             data = stream.read(chunk_size)             frames.append(data)     finally:         stream.stop_stream()         stream.close()         p.terminate()              container = io.BytesIO()     wf = wave.open(container, 'wb')     wf.setnchannels(num_channels)     wf.setsampwidth(p.get_sample_size(pyaudio.paInt16))     wf.setframerate(sample_rate)     wf.writeframes(b''.join(frames))     container.seek(0)     return container  sample_rate = 16000 # \u0447\u0430\u0441\u0442\u043e\u0442\u0430 \u0434\u0438\u0441\u043a\u0440\u0435\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043e\u043b\u0436\u043d\u0430                      # \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0442\u044c \u043f\u0440\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0438 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0438      # \u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0430\u0443\u0434\u0438\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e 3 \u0441\u0435\u043a\u0443\u043d\u0434\u044b data = record_audio(3, sample_rate)  # \u041e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0430 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435 text = recognizeShortAudio.recognize(     data, format='lpcm', sampleRateHertz=sample_rate) print(text)<\/code><\/pre>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0435. \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0432\u0430\u043c \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u043b\u0430\u0441\u044c <a href=\"https:\/\/github.com\/TikhonP\/yandex-speechkit-lib-python\" rel=\"noopener noreferrer nofollow\">\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430<\/a> : ) \u0411\u0443\u0434\u0443 \u0440\u0430\u0434 \u043f\u0443\u043b-\u0440\u0435\u043a\u0432\u0435\u0441\u0442\u0430\u043c!<\/p>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435!<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/681566\/\"> https:\/\/habr.com\/ru\/post\/681566\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-336769","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/336769","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=336769"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/336769\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=336769"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=336769"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=336769"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}