{"id":463812,"date":"2025-06-19T03:01:52","date_gmt":"2025-06-19T03:01:52","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=463812"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2025-06-19T03:01:52","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=463812","title":{"rendered":"<span>\u041f\u0438\u0448\u0435\u043c \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e AI-\u0430\u0441\u0441\u0438\u0441\u0442\u0435\u043d\u0442\u0430 \u043d\u0430 Python<\/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>\u0421\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u044b\u0435 \u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u0438 \u044d\u0442\u043e \u043c\u043e\u0449\u043d\u044b\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0441\u043e\u0447\u0435\u0442\u0430\u044e\u0449\u0438\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0440\u0435\u0447\u0438, \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0438 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044e \u0441 \u0432\u043d\u0435\u0448\u043d\u0438\u043c\u0438 API. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0430\u0441\u0441\u0438\u0441\u0442\u0435\u043d\u0442\u0430 \u043d\u0430 Python, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 whisper, webrtcvad, gTTS \u0438 \u0434\u0440\u0443\u0433\u0438\u0435. \u041d\u0430\u0448 \u0430\u0441\u0441\u0438\u0441\u0442\u0435\u043d\u0442 \u0431\u0443\u0434\u0435\u0442:<\/p>\n<ul>\n<li>\n<p>\u0421\u043b\u0443\u0448\u0430\u0442\u044c \u043c\u0438\u043a\u0440\u043e\u0444\u043e\u043d<\/p>\n<\/li>\n<li>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u043d\u0430\u0447\u0430\u043b\u043e \u0438 \u043a\u043e\u043d\u0435\u0446 \u0440\u0435\u0447\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e VAD (Voice Activity Detection)<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0440\u0435\u0447\u044c \u0432 \u0442\u0435\u043a\u0441\u0442 \u0447\u0435\u0440\u0435\u0437 \u043c\u043e\u0434\u0435\u043b\u044c Whisper<\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 LLM \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043e\u0442\u0432\u0435\u0442\u0430<\/p>\n<\/li>\n<li>\n<p>\u0427\u0438\u0442\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442 \u0432\u0441\u043b\u0443\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e gTTS<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u0442\u044c\/\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c \u043f\u043e \u043a\u043b\u0430\u0432\u0438\u0448\u0435 \u043f\u0440\u043e\u0431\u0435\u043b<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u043e\u0435\u043a\u0442 \u043c\u043e\u0436\u0435\u0442 \u0441\u043b\u0443\u0436\u0438\u0442\u044c \u043a\u0430\u043a \u043d\u0430\u0447\u0430\u043b\u043e\u043c \u0434\u043b\u044f \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432, \u0442\u0430\u043a \u0438 \u0434\u043b\u044f \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439.<\/p>\n<p>\ud83d\udd27 \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439<\/p>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u043c \u0443\u0431\u0435\u0434\u0438\u0442\u0435\u0441\u044c, \u0447\u0442\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u044b \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438:<\/p>\n<pre><code class=\"bash\">pip install numpy sounddevice keyboard whisper torch webrtcvad requests colorama gTTS<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u0441 LLM, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <a href=\"https:\/\/github.com\/ggerganov\/llama.cpp\" rel=\"noopener noreferrer nofollow\">LM Studio<\/a>, \u0441\u043b\u0443\u0448\u0430\u044e\u0449\u0438\u0439 \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 <a href=\"http:\/\/localhost:1234\" rel=\"noopener noreferrer nofollow\"><code>http:\/\/localhost:1234<\/code><\/a>.  <\/p>\n<p>\ud83c\udfa4 \u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0437\u0432\u0443\u043a\u0430 \u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u0433\u043e\u043b\u043e\u0441\u0430<\/p>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0430\u0443\u0434\u0438\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 sounddevice. \u041c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043f\u043e\u0442\u043e\u043a \u0437\u0430\u043f\u0438\u0441\u0438 \u0441 \u0447\u0430\u0441\u0442\u043e\u0442\u043e\u0439 16 \u043a\u0413\u0446 \u0438 \u043e\u0436\u0438\u0434\u0430\u0435\u043c \u043d\u0430\u0436\u0430\u0442\u0438\u0435 \u043f\u0440\u043e\u0431\u0435\u043b\u0430 \u2014 \u044d\u0442\u043e \u043d\u0430\u0448 \u0442\u0440\u0438\u0433\u0433\u0435\u0440 \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430\/\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0437\u0430\u043f\u0438\u0441\u0438.<\/p>\n<pre><code class=\"python\">def record_audio():     global recording     print(\"\u041d\u0430\u0436\u043c\u0438\u0442\u0435 \u041f\u0440\u043e\u0431\u0435\u043b \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u043f\u0438\u0441\u0438...\")     with sd.InputStream(samplerate=SAMPLE_RATE, channels=CHANNELS, dtype=DTYPE, callback=callback):         while True:             if keyboard.is_pressed('space'):                 toggle_recording()                 while keyboard.is_pressed('space'):                     pass             time.sleep(0.1)<\/code><\/pre>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u0430\u0443\u0434\u0438\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0431\u0443\u0444\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u0442\u0435\u043c \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e VAD (webrtcvad) \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u043b\u0438\u0447\u0438\u044f \u0440\u0435\u0447\u0438.<\/p>\n<p>\ud83d\udde3\ufe0f \u0420\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435 \u0440\u0435\u0447\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Whisper<\/p>\n<p>Whisper \u2014 \u043e\u0434\u043d\u0430 \u0438\u0437 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u044f \u0440\u0435\u0447\u0438. \u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0435\u0451 \u0447\u0435\u0440\u0435\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 whisper, \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c medium \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u0435\u043b\u044c (GPU), \u0435\u0441\u043b\u0438 \u043e\u043d \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d.<\/p>\n<pre><code class=\"python\">model = whisper.load_model(\"medium\").to(device)<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u0440\u0435\u0447\u0438 (\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e \u043f\u0430\u0443\u0437\u0430\u043c) \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u0432 \u043c\u043e\u0434\u0435\u043b\u044c:<\/p>\n<pre><code class=\"python\">result = model.transcribe(audio_float, language=\"ru\", verbose=None) text = result[\"text\"].strip()<\/code><\/pre>\n<p>\ud83d\udcac \u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u0430 \u043e\u0442 \u0418\u0418<\/p>\n<p>\u0414\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043e\u0442\u0432\u0435\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c g<em>oogle\/gemma-3-4B <\/em>\u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 LM Studio , \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c LLM-\u043c\u043e\u0434\u0435\u043b\u0438  \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e \u043d\u0430 \u043d\u0430\u0448\u0435\u0439 \u043c\u0430\u0448\u0438\u043d\u0435 \u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u0439 \u0441 OpenAI API \u0441\u0435\u0440\u0432\u0435\u0440.<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 google\/gemma-3-4b \u0432 LM Studio, \u0432\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0435\u0451 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430. HTTP-\u0441\u0435\u0440\u0432\u0435\u0440 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 JSON-\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 <a href=\"http:\/\/localhost:1234\/v1\/chat\/completions\" rel=\"noopener noreferrer nofollow\">http:\/\/localhost:1234\/v1\/chat\/completions<\/a>. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043d\u0430\u0448 Python-\u0441\u043a\u0440\u0438\u043f\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0442\u0443\u0434\u0430 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441, \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u043e\u0442 \u043c\u043e\u0434\u0435\u043b\u0438:<\/p>\n<pre><code class=\"python\">def generate_response(text):     data = {         \"messages\": [{\"role\": \"user\", \"content\": text}],     }     response = requests.post(\"http:\/\/localhost:1234\/v1\/chat\/completions\", json=data)     return response.json()['choices'][0]['message']['content']<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043c\u043e\u0449\u043d\u043e\u0439 \u0418\u0418-\u043c\u043e\u0434\u0435\u043b\u044c\u044e \u0431\u0435\u0437 \u0432\u044b\u0445\u043e\u0434\u0430 \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044f \u043a\u043e\u043d\u0444\u0438\u0434\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044f \u043f\u0440\u0438\u0435\u043c\u043b\u0435\u043c\u0443\u044e \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b (\u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430 \u0438 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043a\u0430\u0440\u0442\u044b). \u0423\u0431\u0435\u0434\u0438\u0442\u0435\u0441\u044c, \u0447\u0442\u043e \u0432 LM Studio \u0432\u044b \u0432\u044b\u0431\u0440\u0430\u043b\u0438 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u043d\u0430\u0436\u0430\u043b\u0438 \u043a\u043d\u043e\u043f\u043a\u0443 Run locally \u0438\u043b\u0438 Start server , \u0447\u0442\u043e\u0431\u044b \u0441\u043a\u0440\u0438\u043f\u0442 \u043c\u043e\u0433 \u0441 \u043d\u0435\u0439 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c.<\/p>\n<p>\ud83c\udfa7 \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0430 \u0432 \u0440\u0435\u0447\u044c (TTS)<\/p>\n<p>\u0414\u043b\u044f \u043e\u0437\u0432\u0443\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 gTTS (Google Text-to-Speech). \u041e\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u0430 \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0438 \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f, (\u043c\u043e\u0434\u0443\u043b\u044c <a href=\"https:\/\/github.com\/vuguzum\/PersonalAssistant\/blob\/main\/gTTS_module.py\" rel=\"noopener noreferrer nofollow\">gTTS_<\/a><a href=\"http:\/\/module.py\" rel=\"noopener noreferrer nofollow\">module.py<\/a>):<\/p>\n<pre><code class=\"python\">import io, os, contextlib from gtts import gTTS import pygame from threading import Thread import keyboard  # \u0414\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u043a\u043b\u0430\u0432\u0438\u0448  # \u0413\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0434\u043b\u044f \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f _playing = False  def text_to_speech_withEsc(text: str, lang: str = 'ru'):     \"\"\"     \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0442\u0435\u043a\u0441\u0442 \u0432 \u0440\u0435\u0447\u044c \u0438 \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u0435\u0433\u043e.     \u041e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u0430 \u043d\u0430\u0436\u0430\u0442\u0438\u0435\u043c \u043a\u043b\u0430\u0432\u0438\u0448\u0438 Esc.     \"\"\"     try:         # \u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0430\u0443\u0434\u0438\u043e \u0432 \u043f\u0430\u043c\u044f\u0442\u044c         tts = gTTS(text=text, lang=lang)         fp = io.BytesIO()         tts.write_to_fp(fp)         fp.seek(0)          # \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f Pygame \u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0430\u0443\u0434\u0438\u043e \u0438\u0437 \u043f\u0430\u043c\u044f\u0442\u0438         pygame.mixer.init()         pygame.mixer.music.load(fp)         pygame.mixer.music.play()          # \u0412\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c, \u043f\u043e\u043a\u0430 \u043d\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442\u0441\u044f \u0438\u043b\u0438 \u043d\u0435 \u043d\u0430\u0436\u043c\u0443\u0442 Esc         while pygame.mixer.music.get_busy():             if keyboard.is_pressed('esc'):                 pygame.mixer.music.stop()                 print(\"\u0412\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043e (Esc)\")                 break          pygame.mixer.quit()      except Exception as e:         print(f\"\u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u043e\u0437\u0432\u0443\u0447\u0438\u0432\u0430\u043d\u0438\u0438: {e}\")     finally:         pass<\/code><\/pre>\n<p>\ud83d\udd8c\ufe0f \u0426\u0432\u0435\u0442\u043e\u0432\u0430\u044f \u0441\u0445\u0435\u043c\u0430 \u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0432\u044b\u0432\u043e\u0434 \u0431\u044b\u043b \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u0447\u0438\u0442\u0430\u0442\u044c, \u043c\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u0446\u0432\u0435\u0442\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e colorama. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u0441\u0432\u0435\u0442\u043b\u043e\u0439 \u0438 \u0442\u0451\u043c\u043d\u043e\u0439 \u0442\u0435\u043c\u043e\u0439 \u043e\u0444\u043e\u0440\u043c\u043b\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"python\">THEMES = {     \"light\": {         \"user\": Fore.BLUE,         \"assistant\": Fore.LIGHTBLACK_EX,         ...     },     \"dark\": {         \"user\": Fore.CYAN,         \"assistant\": Fore.LIGHTGREEN_EX,         ...     } }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u044f \u00ab\u0434\u0443\u043c\u0430\u044e\u0449\u0435\u0433\u043e\u00bb \u0430\u0441\u0441\u0438\u0441\u0442\u0435\u043d\u0442\u0430 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043e\u0442\u0432\u0435\u0442\u0430:<\/p>\n<pre><code class=\"python\">loading_animation(duration=1, text=\"\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u0430...\")<\/code><\/pre>\n<p>\ud83d\ude80 \u0417\u0430\u043f\u0443\u0441\u043a \u0438 \u0440\u0430\u0431\u043e\u0442\u0430<\/p>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 LLM \u0441\u0435\u0440\u0432\u0435\u0440 \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0441\u043a\u0440\u0438\u043f\u0442, \u043d\u0430\u0436\u043c\u0438\u0442\u0435 \u041f\u0440\u043e\u0431\u0435\u043b \u2014 \u0438 \u0437\u0430\u0434\u0430\u0439\u0442\u0435 \u0432\u043e\u043f\u0440\u043e\u0441. \u0410\u0441\u0441\u0438\u0441\u0442\u0435\u043d\u0442 \u0435\u0433\u043e \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0435\u0442, \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442 \u0432 \u043c\u043e\u0434\u0435\u043b\u044c, \u043f\u043e\u043b\u0443\u0447\u0438\u0442 \u043e\u0442\u0432\u0435\u0442 \u0438 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0435\u0442 \u0435\u0433\u043e \u0432\u0430\u043c \u0432\u0441\u043b\u0443\u0445 (\u0444\u0430\u0439\u043b <em>pers_assist.py<\/em>). <\/p>\n<pre><code class=\"python\">import numpy as np import sounddevice as sd import keyboard import whisper import threading import time import torch import webrtcvad import requests from colorama import Fore, Style, init import time import sounddevice as sd import re import gTTS_module2   # \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f colorama init(autoreset=True)  # === \u0426\u0432\u0435\u0442\u043e\u0432\u044b\u0435 \u0441\u0445\u0435\u043c\u044b === THEMES = {     \"light\": {         \"user\": Fore.BLUE,         \"assistant\": Fore.LIGHTBLACK_EX,         \"thinking\": Fore.MAGENTA,         \"background\": Style.BRIGHT,         \"prompt\": \"\u0421\u0432\u0435\u0442\u043b\u0430\u044f\"     },     \"dark\": {         \"user\": Fore.CYAN,         \"assistant\": Fore.LIGHTGREEN_EX,         \"thinking\": Fore.YELLOW,         \"background\": Style.DIM,         \"prompt\": \"\u0422\u0451\u043c\u043d\u0430\u044f\"     } }  THEME = THEMES[\"light\"] #print(f\"\\n\u2705 \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0430 {THEME['prompt']} \u0442\u0435\u043c\u0430\\n\")    # --- \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 --- SAMPLE_RATE = 16000 CHANNELS = 1 DTYPE = np.int16  SEGMENT_DURATION = 0.02  # 20 \u043c\u0441 \u0434\u043b\u044f VAD SEGMENT_SAMPLES = int(SAMPLE_RATE * SEGMENT_DURATION)  MIN_SPEECH_CHUNKS = 10     # \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u043e\u0432 \u0441 \u0433\u043e\u043b\u043e\u0441\u043e\u043c \u043f\u043e\u0434\u0440\u044f\u0434 SILENCE_TIMEOUT = 1.5      # \u0441\u0435\u043a\u0443\u043d\u0434 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u0434 \u043d\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0439    #['tiny.en', 'tiny', 'base.en', 'base', 'small.en', 'small', 'medium.en', 'medium', 'large-v1', 'large-v2', 'large-v3', 'large', 'large-v3-turbo', 'turbo']   # --- \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 Whisper \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 CUDA --- device = \"cuda\" if torch.cuda.is_available() else \"cpu\" #print(f\"[\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e]: {device.upper()}\") model = whisper.load_model(\"medium\").to(device)  #\u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a: model = whisper.load_model(\"small\", device=\"cpu\")   # --- \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f VAD --- vad = webrtcvad.Vad() vad.set_mode(3 )  # \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c 0 - \u0432\u044b\u0441\u043e\u043a\u0430\u044f, 3 - \u043d\u0438\u0437\u043a\u0430\u044f    def is_speech(frame_bytes):     try:         return vad.is_speech(frame_bytes, SAMPLE_RATE)     except:          return False    # --- \u0413\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 --- recording = False audio_buffer = [] buffer_index = 0  lock = threading.Lock() last_speech_time = None  # --- Callback \u0437\u0430\u043f\u0438\u0441\u0438 --- def callback(indata, frames, time, status):     if recording:         with lock:             audio_buffer.extend(indata.copy().flatten())  # --- \u0423\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0438\u0441\u044c\u044e --- def record_audio():     global recording     print(\"\u041d\u0430\u0436\u043c\u0438\u0442\u0435 \u041f\u0440\u043e\u0431\u0435\u043b \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u043f\u0438\u0441\u0438...\")     with sd.InputStream(samplerate=SAMPLE_RATE, channels=CHANNELS, dtype=DTYPE, callback=callback):         while True:             if keyboard.is_pressed('space'):                 toggle_recording()                 while keyboard.is_pressed('space'):                     pass             time.sleep(0.1)  def toggle_recording():     global recording, audio_buffer, buffer_index     global speech_segment, speech_started, new_line_pending, current_pause, last_speech_time      recording = not recording     if recording:         print(\"\\n[\u0417\u0430\u043f\u0438\u0441\u044c \u043d\u0430\u0447\u0430\u043b\u0430\u0441\u044c...]\")         audio_buffer.clear()         buffer_index = 0          # \u0421\u0431\u0440\u043e\u0441 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f VAD         speech_segment = []            speech_started = False             new_line_pending = False         current_pause = 0.0         last_speech_time = time.time()  # \u2190 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u0447\u0430\u043b\u0430      else:         print(\"[\u0417\u0430\u043f\u0438\u0441\u044c \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0430.]\")    def generate_response(text):     data = {      \"messages\": [         {\"role\": \"user\", \"content\": text}            ],     #\"temperature\": 0.0,        # \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0441\u0442\u044c     #\"max_tokens\": 10,          # \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0434\u043b\u044f \u043e\u0442\u0432\u0435\u0442\u0430     #\"stream\": False,           # \u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043f\u043e\u0442\u043e\u043a\u043e\u0432\u0443\u044e \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0443     #\"stop\": [\"\\n\"]             # \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438      }      response = requests.post(         \"http:\/\/localhost:1234\/v1\/chat\/completions\",         json=data     )     assist_reply = response.json()['choices'][0]['message']['content']     # \u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0442\u0435\u0433\u0438 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u044b\u043c \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438     #cleaned_text = re.sub(r'\\&lt;think\\&gt;.*?&lt;\\&lt;\/think\\&gt;', '', assist_reply, flags=re.DOTALL)     #print(\"\u041e\u0442\u0432\u0435\u0442 \u0430\u0441\u0441\u0438\u0441\u0442\u0435\u043d\u0442\u0430:\", assist_reply)      return assist_reply   # === \u0410\u043d\u0438\u043c\u0430\u0446\u0438\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 === def loading_animation(duration=1 , text=\"\u0414\u0443\u043c\u0430\u044e\"):     symbols = [ '\u28f7', '\u28ef', '\u28df', '\u287f', '\u28bf', '\u28fb', '\u28fd','\u28fe']     end_time = time.time() + duration     idx = 0     while time.time() &lt; end_time:         print(f\"\\r{THEME['thinking']}[{symbols[idx % len(symbols)]}] {text}{Style.RESET_ALL}\", end=\"\")         idx += 1         time.sleep(0.1)     print(\" \" * (len(text) + 6), end=\"\\r\")  # \u041e\u0447\u0438\u0441\u0442\u043a\u0430 \u0441\u0442\u0440\u043e\u043a\u0438    def process_stream():     global last_speech_time, buffer_index     global speech_segment, speech_started, new_line_pending, current_pause     global recording         while True:         if not recording:             time.sleep(0.5)             continue         question_text = \"\"                 with lock:             available = len(audio_buffer)          while buffer_index + SEGMENT_SAMPLES &lt;= available:             segment = audio_buffer[buffer_index:buffer_index + SEGMENT_SAMPLES]             buffer_index += SEGMENT_SAMPLES              segment_np = np.array(segment, dtype=np.int16)             frame_bytes = segment_np.tobytes()              try:                 is_silence = not is_speech(frame_bytes)                  if not is_silence:                     speech_segment.extend(segment)                     speech_started = True                     new_line_pending = False                     last_speech_time = time.time()  # \u2190 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0432\u0440\u0435\u043c\u044f \u0440\u0435\u0447\u0438                 elif speech_started:                     current_pause = time.time() - last_speech_time                      if current_pause &gt; SILENCE_TIMEOUT:                         if speech_segment:                             # \u0420\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0451\u043c \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u043c                             audio_float = np.array(speech_segment, dtype=np.float32) \/ 32768.0                             result = model.transcribe(audio_float, language=\"ru\", verbose=None)                              text = result[\"text\"].strip()                             if text.startswith(\"\u0420\u0435\u0434\u0430\u043a\u0442\u043e\u0440 \u0441\u0443\u0431\u0442\u0438\u0442\u0440\u043e\u0432\"): # \u0431\u0430\u0433 whisper, \u0440\u0435\u0430\u043a\u0446\u0438\u044f \u043d\u0430 \u0448\u0443\u043c                                 text = \"\"                                 continue                             question_text += \" \" + text                                 if text:                                 print(f\"{THEME['user']}\u0412\u044b: {Style.RESET_ALL}{text}\" , end=\" \", flush=True)                                                              speech_segment = []                          print()  # \u043d\u043e\u0432\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430                         speech_segment = []                         speech_started = False                         new_line_pending = False                          # \u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u0430                         loading_animation(text=\"\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u0430...\")                         #print(f\"\\r{THEME['thinking']}[{symbols[idx % len(symbols)]}] {text}{Style.RESET_ALL}\", end=\"\")                         #print(f\"{THINKING_COLOR}\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u0430...{RESET}\", end=\"\\r\")                         response = generate_response(question_text)                          print(f\"{THEME['assistant']}\u0410\u0441\u0441\u0438\u0441\u0442\u0435\u043d\u0442: {response}{Style.RESET_ALL}\")                         question_text = \"\"                          recording = False                         gTTS_module2.text_to_speech_withEsc(response)                         recording = True                    except Exception as e:                  print(f\"[\u041e\u0448\u0438\u0431\u043a\u0430]: {e}\")         time.sleep(0.05)  # --- \u0422\u043e\u0447\u043a\u0430 \u0432\u0445\u043e\u0434\u0430 --- if __name__ == \"__main__\":     print(\"[Voice-assisient \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043e.]\")     threading.Thread(target=record_audio, daemon=True).start()     threading.Thread(target=process_stream, daemon=True).start()      try:         while True:             time.sleep(1)     except KeyboardInterrupt:         print(\"\\n\u0412\u044b\u0445\u043e\u0434.\")<\/code><\/pre>\n<p>\u2705 \u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/p>\n<p>\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043d\u0430 <a href=\"https:\/\/github.com\/vuguzum\/PersonalAssistant\" rel=\"noopener noreferrer nofollow\">github<\/a>. \u0421\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043d\u0430\u043c\u0438 \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u043e\u0439 \u0430\u0441\u0441\u0438\u0441\u0442\u0435\u043d\u0442 \u2014 \u044d\u0442\u043e \u043f\u0438\u043b\u043e\u0442\u043d\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u0442\u044c \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0433\u043e AI-\u0430\u0441\u0441\u0438\u0441\u0442\u0435\u043d\u0442\u0430 \u0434\u043b\u044f \u0434\u043e\u043c\u0430 \u0438\u043b\u0438 \u043e\u0444\u0438\u0441\u0430. \u041e\u043d \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0439: \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0437\u0432\u0443\u043a\u0430, \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0438 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 API. \u041f\u0440\u043e\u0435\u043a\u0442 \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u043e\u0439 \u0434\u043b\u044f \u0442\u0435\u0445 \u043a\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442\u0441\u044f \u0442\u0435\u043c\u043e\u0439 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u0430\u0441\u0441\u0438\u0441\u0442\u0435\u043d\u0442\u043e\u0432.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/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\/articles\/919720\/\"> https:\/\/habr.com\/ru\/articles\/919720\/<\/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>\u0421\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u044b\u0435 \u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u0438 \u044d\u0442\u043e \u043c\u043e\u0449\u043d\u044b\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0441\u043e\u0447\u0435\u0442\u0430\u044e\u0449\u0438\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0440\u0435\u0447\u0438, \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0438 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044e \u0441 \u0432\u043d\u0435\u0448\u043d\u0438\u043c\u0438 API. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0430\u0441\u0441\u0438\u0441\u0442\u0435\u043d\u0442\u0430 \u043d\u0430 Python, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 whisper, webrtcvad, gTTS \u0438 \u0434\u0440\u0443\u0433\u0438\u0435. \u041d\u0430\u0448 \u0430\u0441\u0441\u0438\u0441\u0442\u0435\u043d\u0442 \u0431\u0443\u0434\u0435\u0442:<\/p>\n<ul>\n<li>\n<p>\u0421\u043b\u0443\u0448\u0430\u0442\u044c \u043c\u0438\u043a\u0440\u043e\u0444\u043e\u043d<\/p>\n<\/li>\n<li>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u043d\u0430\u0447\u0430\u043b\u043e \u0438 \u043a\u043e\u043d\u0435\u0446 \u0440\u0435\u0447\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e VAD (Voice Activity Detection)<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0440\u0435\u0447\u044c \u0432 \u0442\u0435\u043a\u0441\u0442 \u0447\u0435\u0440\u0435\u0437 \u043c\u043e\u0434\u0435\u043b\u044c Whisper<\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 LLM \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043e\u0442\u0432\u0435\u0442\u0430<\/p>\n<\/li>\n<li>\n<p>\u0427\u0438\u0442\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442 \u0432\u0441\u043b\u0443\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e gTTS<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u0442\u044c\/\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c \u043f\u043e \u043a\u043b\u0430\u0432\u0438\u0448\u0435 \u043f\u0440\u043e\u0431\u0435\u043b<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u043e\u0435\u043a\u0442 \u043c\u043e\u0436\u0435\u0442 \u0441\u043b\u0443\u0436\u0438\u0442\u044c \u043a\u0430\u043a \u043d\u0430\u0447\u0430\u043b\u043e\u043c \u0434\u043b\u044f \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432, \u0442\u0430\u043a \u0438 \u0434\u043b\u044f \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439.<\/p>\n<p>\ud83d\udd27 \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439<\/p>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u043c \u0443\u0431\u0435\u0434\u0438\u0442\u0435\u0441\u044c, \u0447\u0442\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u044b \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438:<\/p>\n<pre><code class=\"bash\">pip install numpy sounddevice keyboard whisper torch webrtcvad requests colorama gTTS<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u0441 LLM, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <a href=\"https:\/\/github.com\/ggerganov\/llama.cpp\" rel=\"noopener noreferrer nofollow\">LM Studio<\/a>, \u0441\u043b\u0443\u0448\u0430\u044e\u0449\u0438\u0439 \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 <a href=\"http:\/\/localhost:1234\" rel=\"noopener noreferrer nofollow\"><code>http:\/\/localhost:1234<\/code><\/a>.  <\/p>\n<p>\ud83c\udfa4 \u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0437\u0432\u0443\u043a\u0430 \u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u0433\u043e\u043b\u043e\u0441\u0430<\/p>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0430\u0443\u0434\u0438\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 sounddevice. \u041c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043f\u043e\u0442\u043e\u043a \u0437\u0430\u043f\u0438\u0441\u0438 \u0441 \u0447\u0430\u0441\u0442\u043e\u0442\u043e\u0439 16 \u043a\u0413\u0446 \u0438 \u043e\u0436\u0438\u0434\u0430\u0435\u043c \u043d\u0430\u0436\u0430\u0442\u0438\u0435 \u043f\u0440\u043e\u0431\u0435\u043b\u0430 \u2014 \u044d\u0442\u043e \u043d\u0430\u0448 \u0442\u0440\u0438\u0433\u0433\u0435\u0440 \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430\/\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0437\u0430\u043f\u0438\u0441\u0438.<\/p>\n<pre><code class=\"python\">def record_audio():     global recording     print(\"\u041d\u0430\u0436\u043c\u0438\u0442\u0435 \u041f\u0440\u043e\u0431\u0435\u043b \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u043f\u0438\u0441\u0438...\")     with sd.InputStream(samplerate=SAMPLE_RATE, channels=CHANNELS, dtype=DTYPE, callback=callback):         while True:             if keyboard.is_pressed('space'):                 toggle_recording()                 while keyboard.is_pressed('space'):                     pass             time.sleep(0.1)<\/code><\/pre>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u0430\u0443\u0434\u0438\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0431\u0443\u0444\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u0442\u0435\u043c \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e VAD (webrtcvad) \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u043b\u0438\u0447\u0438\u044f \u0440\u0435\u0447\u0438.<\/p>\n<p>\ud83d\udde3\ufe0f \u0420\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435 \u0440\u0435\u0447\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Whisper<\/p>\n<p>Whisper \u2014 \u043e\u0434\u043d\u0430 \u0438\u0437 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u044f \u0440\u0435\u0447\u0438. \u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0435\u0451 \u0447\u0435\u0440\u0435\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 whisper, \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c medium \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u0435\u043b\u044c (GPU), \u0435\u0441\u043b\u0438 \u043e\u043d \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d.<\/p>\n<pre><code class=\"python\">model = whisper.load_model(\"medium\").to(device)<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u0440\u0435\u0447\u0438 (\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e \u043f\u0430\u0443\u0437\u0430\u043c) \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u0432 \u043c\u043e\u0434\u0435\u043b\u044c:<\/p>\n<pre><code class=\"python\">result = model.transcribe(audio_float, language=\"ru\", verbose=None) text = result[\"text\"].strip()<\/code><\/pre>\n<p>\ud83d\udcac \u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u0430 \u043e\u0442 \u0418\u0418<\/p>\n<p>\u0414\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043e\u0442\u0432\u0435\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c g<em>oogle\/gemma-3-4B <\/em>\u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 LM Studio , \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c LLM-\u043c\u043e\u0434\u0435\u043b\u0438  \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e \u043d\u0430 \u043d\u0430\u0448\u0435\u0439 \u043c\u0430\u0448\u0438\u043d\u0435 \u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u0439 \u0441 OpenAI API \u0441\u0435\u0440\u0432\u0435\u0440.<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 google\/gemma-3-4b \u0432 LM Studio, \u0432\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0435\u0451 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430. HTTP-\u0441\u0435\u0440\u0432\u0435\u0440 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 JSON-\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 <a href=\"http:\/\/localhost:1234\/v1\/chat\/completions\" rel=\"noopener noreferrer nofollow\">http:\/\/localhost:1234\/v1\/chat\/completions<\/a>. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043d\u0430\u0448 Python-\u0441\u043a\u0440\u0438\u043f\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0442\u0443\u0434\u0430 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441, \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u043e\u0442 \u043c\u043e\u0434\u0435\u043b\u0438:<\/p>\n<pre><code class=\"python\">def generate_response(text):     data = {         \"messages\": [{\"role\": \"user\", \"content\": text}],     }     response = requests.post(\"http:\/\/localhost:1234\/v1\/chat\/completions\", json=data)     return response.json()['choices'][0]['message']['content']<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043c\u043e\u0449\u043d\u043e\u0439 \u0418\u0418-\u043c\u043e\u0434\u0435\u043b\u044c\u044e \u0431\u0435\u0437 \u0432\u044b\u0445\u043e\u0434\u0430 \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044f \u043a\u043e\u043d\u0444\u0438\u0434\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044f \u043f\u0440\u0438\u0435\u043c\u043b\u0435\u043c\u0443\u044e \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b (\u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430 \u0438 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043a\u0430\u0440\u0442\u044b). \u0423\u0431\u0435\u0434\u0438\u0442\u0435\u0441\u044c, \u0447\u0442\u043e \u0432 LM Studio \u0432\u044b \u0432\u044b\u0431\u0440\u0430\u043b\u0438 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u043d\u0430\u0436\u0430\u043b\u0438 \u043a\u043d\u043e\u043f\u043a\u0443 Run locally \u0438\u043b\u0438 Start server , \u0447\u0442\u043e\u0431\u044b \u0441\u043a\u0440\u0438\u043f\u0442 \u043c\u043e\u0433 \u0441 \u043d\u0435\u0439 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c.<\/p>\n<p>\ud83c\udfa7 \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0430 \u0432 \u0440\u0435\u0447\u044c (TTS)<\/p>\n<p>\u0414\u043b\u044f \u043e\u0437\u0432\u0443\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 gTTS (Google Text-to-Speech). \u041e\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u0430 \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0438 \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f, (\u043c\u043e\u0434\u0443\u043b\u044c <a href=\"https:\/\/github.com\/vuguzum\/PersonalAssistant\/blob\/main\/gTTS_module.py\" rel=\"noopener noreferrer nofollow\">gTTS_<\/a><a href=\"http:\/\/module.py\" rel=\"noopener noreferrer nofollow\">module.py<\/a>):<\/p>\n<pre><code class=\"python\">import io, os, contextlib from gtts import gTTS import pygame from threading import Thread import keyboard  # \u0414\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u043a\u043b\u0430\u0432\u0438\u0448  # \u0413\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0434\u043b\u044f \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f _playing = False  def text_to_speech_withEsc(text: str, lang: str = 'ru'):     \"\"\"     \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0442\u0435\u043a\u0441\u0442 \u0432 \u0440\u0435\u0447\u044c \u0438 \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u0435\u0433\u043e.     \u041e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u0430 \u043d\u0430\u0436\u0430\u0442\u0438\u0435\u043c \u043a\u043b\u0430\u0432\u0438\u0448\u0438 Esc.     \"\"\"     try:         # \u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0430\u0443\u0434\u0438\u043e \u0432 \u043f\u0430\u043c\u044f\u0442\u044c         tts = gTTS(text=text, lang=lang)         fp = io.BytesIO()         tts.write_to_fp(fp)         fp.seek(0)          # \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f Pygame \u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0430\u0443\u0434\u0438\u043e \u0438\u0437 \u043f\u0430\u043c\u044f\u0442\u0438         pygame.mixer.init()         pygame.mixer.music.load(fp)         pygame.mixer.music.play()          # \u0412\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c, \u043f\u043e\u043a\u0430 \u043d\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442\u0441\u044f \u0438\u043b\u0438 \u043d\u0435 \u043d\u0430\u0436\u043c\u0443\u0442 Esc         while pygame.mixer.music.get_busy():             if keyboard.is_pressed('esc'):                 pygame.mixer.music.stop()                 print(\"\u0412\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043e (Esc)\")                 break          pygame.mixer.quit()      except Exception as e:         print(f\"\u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u043e\u0437\u0432\u0443\u0447\u0438\u0432\u0430\u043d\u0438\u0438: {e}\")     finally:         pass<\/code><\/pre>\n<p>\ud83d\udd8c\ufe0f \u0426\u0432\u0435\u0442\u043e\u0432\u0430\u044f \u0441\u0445\u0435\u043c\u0430 \u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0432\u044b\u0432\u043e\u0434 \u0431\u044b\u043b \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u0447\u0438\u0442\u0430\u0442\u044c, \u043c\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u0446\u0432\u0435\u0442\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e colorama. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u0441\u0432\u0435\u0442\u043b\u043e\u0439 \u0438 \u0442\u0451\u043c\u043d\u043e\u0439 \u0442\u0435\u043c\u043e\u0439 \u043e\u0444\u043e\u0440\u043c\u043b\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"python\">THEMES = {     \"light\": {         \"user\": Fore.BLUE,         \"assistant\": Fore.LIGHTBLACK_EX,         ...     },     \"dark\": {         \"user\": Fore.CYAN,         \"assistant\": Fore.LIGHTGREEN_EX,         ...     } }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u044f \u00ab\u0434\u0443\u043c\u0430\u044e\u0449\u0435\u0433\u043e\u00bb \u0430\u0441\u0441\u0438\u0441\u0442\u0435\u043d\u0442\u0430 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043e\u0442\u0432\u0435\u0442\u0430:<\/p>\n<pre><code class=\"python\">loading_animation(duration=1, text=\"\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u0430...\")<\/code><\/pre>\n<p>\ud83d\ude80 \u0417\u0430\u043f\u0443\u0441\u043a \u0438 \u0440\u0430\u0431\u043e\u0442\u0430<\/p>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 LLM \u0441\u0435\u0440\u0432\u0435\u0440 \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0441\u043a\u0440\u0438\u043f\u0442, \u043d\u0430\u0436\u043c\u0438\u0442\u0435 \u041f\u0440\u043e\u0431\u0435\u043b \u2014 \u0438 \u0437\u0430\u0434\u0430\u0439\u0442\u0435 \u0432\u043e\u043f\u0440\u043e\u0441. \u0410\u0441\u0441\u0438\u0441\u0442\u0435\u043d\u0442 \u0435\u0433\u043e \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0435\u0442, \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442 \u0432 \u043c\u043e\u0434\u0435\u043b\u044c, \u043f\u043e\u043b\u0443\u0447\u0438\u0442 \u043e\u0442\u0432\u0435\u0442 \u0438 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0435\u0442 \u0435\u0433\u043e \u0432\u0430\u043c \u0432\u0441\u043b\u0443\u0445 (\u0444\u0430\u0439\u043b <em>pers_assist.py<\/em>). <\/p>\n<pre><code class=\"python\">import numpy as np import sounddevice as sd import keyboard import whisper import threading import time import torch import webrtcvad import requests from colorama import Fore, Style, init import time import sounddevice as sd import re import gTTS_module2   # \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f colorama init(autoreset=True)  # === \u0426\u0432\u0435\u0442\u043e\u0432\u044b\u0435 \u0441\u0445\u0435\u043c\u044b === THEMES = {     \"light\": {         \"user\": Fore.BLUE,         \"assistant\": Fore.LIGHTBLACK_EX,         \"thinking\": Fore.MAGENTA,         \"background\": Style.BRIGHT,         \"prompt\": \"\u0421\u0432\u0435\u0442\u043b\u0430\u044f\"     },     \"dark\": {         \"user\": Fore.CYAN,         \"assistant\": Fore.LIGHTGREEN_EX,         \"thinking\": Fore.YELLOW,         \"background\": Style.DIM,         \"prompt\": \"\u0422\u0451\u043c\u043d\u0430\u044f\"     } }  THEME = THEMES[\"light\"] #print(f\"\\n\u2705 \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0430 {THEME['prompt']} \u0442\u0435\u043c\u0430\\n\")    # --- \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 --- SAMPLE_RATE = 16000 CHANNELS = 1 DTYPE = np.int16  SEGMENT_DURATION = 0.02  # 20 \u043c\u0441 \u0434\u043b\u044f VAD SEGMENT_SAMPLES = int(SAMPLE_RATE * SEGMENT_DURATION)  MIN_SPEECH_CHUNKS = 10     # \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u043e\u0432 \u0441 \u0433\u043e\u043b\u043e\u0441\u043e\u043c \u043f\u043e\u0434\u0440\u044f\u0434 SILENCE_TIMEOUT = 1.5      # \u0441\u0435\u043a\u0443\u043d\u0434 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u0434 \u043d\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0439    #['tiny.en', 'tiny', 'base.en', 'base', 'small.en', 'small', 'medium.en', 'medium', 'large-v1', 'large-v2', 'large-v3', 'large', 'large-v3-turbo', 'turbo']   # --- \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 Whisper \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 CUDA --- device = \"cuda\" if torch.cuda.is_available() else \"cpu\" #print(f\"[\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e]: {device.upper()}\") model = whisper.load_model(\"medium\").to(device)  #\u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a: model = whisper.load_model(\"small\", device=\"cpu\")   # --- \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f VAD --- vad = webrtcvad.Vad() vad.set_mode(3 )  # \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c 0 - \u0432\u044b\u0441\u043e\u043a\u0430\u044f, 3 - \u043d\u0438\u0437\u043a\u0430\u044f    def is_speech(frame_bytes):     try:         return vad.is_speech(frame_bytes, SAMPLE_RATE)     except:          return False    # --- \u0413\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 --- recording = False audio_buffer = [] buffer_index = 0  lock = threading.Lock() last_speech_time = None  # --- Callback \u0437\u0430\u043f\u0438\u0441\u0438 --- def callback(indata, frames, time, status):     if recording:         with lock:             audio_buffer.extend(indata.copy().flatten())  # --- \u0423\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0438\u0441\u044c\u044e --- def record_audio():     global recording     print(\"\u041d\u0430\u0436\u043c\u0438\u0442\u0435 \u041f\u0440\u043e\u0431\u0435\u043b \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u043f\u0438\u0441\u0438...\")     with sd.InputStream(samplerate=SAMPLE_RATE, channels=CHANNELS, dtype=DTYPE, callback=callback):         while True:             if keyboard.is_pressed('space'):                 toggle_recording()                 while keyboard.is_pressed('space'):                     pass             time.sleep(0.1)  def toggle_recording():     global recording, audio_buffer, buffer_index     global speech_segment, speech_started, new_line_pending, current_pause, last_speech_time      recording = not recording     if recording:         print(\"\\n[\u0417\u0430\u043f\u0438\u0441\u044c \u043d\u0430\u0447\u0430\u043b\u0430\u0441\u044c...]\")         audio_buffer.clear()         buffer_index = 0          # \u0421\u0431\u0440\u043e\u0441 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f VAD         speech_segment = []            speech_started = False             new_line_pending = False         current_pause = 0.0         last_speech_time = time.time()  # \u2190 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u0447\u0430\u043b\u0430      else:         print(\"[\u0417\u0430\u043f\u0438\u0441\u044c \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0430.]\")    def generate_response(text):     data = {      \"messages\": [         {\"role\": \"user\", \"content\": text}            ],     #\"temperature\": 0.0,        # \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0441\u0442\u044c     #\"max_tokens\": 10,          # \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0434\u043b\u044f \u043e\u0442\u0432\u0435\u0442\u0430     #\"stream\": False,           # \u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043f\u043e\u0442\u043e\u043a\u043e\u0432\u0443\u044e \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0443     #\"stop\": [\"\\n\"]             # \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438      }      response = requests.post(         \"http:\/\/localhost:1234\/v1\/chat\/completions\",         json=data     )     assist_reply = response.json()['choices'][0]['message']['content']     # \u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0442\u0435\u0433\u0438 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u044b\u043c \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438     #cleaned_text = re.sub(r'\\&lt;think\\&gt;.*?&lt;\\&lt;\/think\\&gt;', '', assist_reply, flags=re.DOTALL)     #print(\"\u041e\u0442\u0432\u0435\u0442 \u0430\u0441\u0441\u0438\u0441\u0442\u0435\u043d\u0442\u0430:\", assist_reply)      return assist_reply   # === \u0410\u043d\u0438\u043c\u0430\u0446\u0438\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 === def loading_animation(duration=1 , text=\"\u0414\u0443\u043c\u0430\u044e\"):     symbols = [ '\u28f7', '\u28ef', '\u28df', '\u287f', '\u28bf', '\u28fb', '\u28fd','\u28fe']     end_time = time.time() + duration     idx = 0     while time.time() &lt; end_time:         print(f\"\\r{THEME['thinking']}[{symbols[idx % len(symbols)]}] {text}{Style.RESET_ALL}\", end=\"\")         idx += 1         time.sleep(0.1)     print(\" \" * (len(text) + 6), end=\"\\r\")  # \u041e\u0447\u0438\u0441\u0442\u043a\u0430 \u0441\u0442\u0440\u043e\u043a\u0438    def process_stream():     global last_speech_time, buffer_index     global speech_segment, speech_started, new_line_pending, current_pause     global recording         while True:         if not recording:             time.sleep(0.5)             continue         question_text = \"\"                 with lock:             available = len(audio_buffer)          while buffer_index + SEGMENT_SAMPLES &lt;= available:             segment =<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\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-463812","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/463812","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=463812"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/463812\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=463812"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=463812"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=463812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}