{"id":134,"date":"2025-04-10T16:11:46","date_gmt":"2025-04-10T08:11:46","guid":{"rendered":"http:\/\/121.43.60.100\/?p=134"},"modified":"2025-07-16T16:22:12","modified_gmt":"2025-07-16T08:22:12","slug":"live-talking%ef%bc%88%e5%bc%80%e6%ba%90%e5%ae%9e%e6%97%b6%e4%ba%92%e5%8a%a8%e6%95%b0%e5%ad%97%e4%ba%ba%e7%9b%b4%e6%92%ad%e7%b3%bb%e7%bb%9f%ef%bc%89%e7%9a%84%e4%bd%bf%e7%94%a8%e6%b3%a8%e6%84%8f","status":"publish","type":"post","link":"https:\/\/ziline.top\/index.php\/2025\/04\/10\/live-talking%ef%bc%88%e5%bc%80%e6%ba%90%e5%ae%9e%e6%97%b6%e4%ba%92%e5%8a%a8%e6%95%b0%e5%ad%97%e4%ba%ba%e7%9b%b4%e6%92%ad%e7%b3%bb%e7%bb%9f%ef%bc%89%e7%9a%84%e4%bd%bf%e7%94%a8%e6%b3%a8%e6%84%8f\/","title":{"rendered":"Live Talking\uff08\u5f00\u6e90\u5b9e\u65f6\u4e92\u52a8\u6570\u5b57\u4eba\u76f4\u64ad\u7cfb\u7edf\uff09\u7684\u4f7f\u7528\u6ce8\u610f\u70b9"},"content":{"rendered":"\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u4e00.pytorch\u548ccuda\u7248\u672c\u4e00\u5b9a\u8981\u5339\u914d\uff0cpython\u7248\u672c\u8981\u5927\u4e8e\u7b49\u4e8e3.9\u3002<\/p>\n\n\n\n<p>\u4e8c.\u5728Live Talking\u6587\u4ef6\u5939\u4e0b\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\uff0c\u8fd0\u884c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python app.py --transport webrtc\n\u5982\u679c\u66f4\u6362\u6210\u9884\u8bbe\u6a21\u578b\uff0c\u4f7f\u7528\uff1a\npython app.py --transport webrtc --model wav2lip --avatar_id wav2lip256_avatar1<\/code><\/pre>\n\n\n\n<p>\uff08\u4f20\u8f93\u6a21\u5f0fWebRTC P2P\uff09<\/p>\n\n\n\n<p>\u4e09.\u4fee\u6539llm.py<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/ziline.top\/wp-content\/uploads\/2025\/04\/image-15.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"99\" height=\"46\" data-original=\"https:\/\/ziline.top\/wp-content\/uploads\/2025\/04\/image-15.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-136\"\/><\/div><\/figure>\n\n\n\n<p>\u4fee\u6539llm.py\u6587\u4ef6\u5185\u5bb9\uff0c\u5168\u90e8\u66ff\u6362\u4e3a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import time\nimport os\nfrom basereal import BaseReal\nfrom logger import logger\n\ndef llm_response(message, nerfreal: BaseReal):\n    start = time.perf_counter()\n    from openai import OpenAI\n    \n    try:\n        client = OpenAI(\n            api_key=\"\u4f60\u7684\u5bc6\u94a5\",\n            base_url=\"\u4f60\u7684\u63a5\u53e3URL\",\n        )\n        end = time.perf_counter()\n        logger.info(f\"llm Time init: {end-start}s\")\n\n        completion = client.chat.completions.create(\n            model=\"DeepSeek-R1\",\n            messages=&#91;\n                {'role': 'system', 'content': '\u4f60\u662f\u4e00\u4e2a\u667a\u80fd\u670d\u52a1\u52a9\u624b.'},\n                {'role': 'user', 'content': message}\n            ],\n            stream=True,\n            stream_options={\"include_usage\": True}\n        )\n\n        result = \"\"\n        first = True\n        \n        # \u65b0\u589e\uff1a\u8c03\u8bd5\u8ba1\u6570\u5668\n        chunk_counter = 0\n        \n        for chunk in completion:\n            chunk_counter += 1\n        \n            # \u8c03\u8bd5\u8f93\u51fa1\uff1a\u6253\u5370\u5b8c\u6574chunk\u7ed3\u6784\n            logger.debug(f\"&#91;Chunk {chunk_counter}] \u539f\u59cb\u7ed3\u6784 &gt;&gt;&gt; {chunk}\")\n            \n            # \u589e\u5f3a\u5224\u65ad\u903b\u8f91\n            if not chunk.choices or len(chunk.choices) == 0:\n                logger.warning(f\"&#91;Chunk {chunk_counter}] \u7a7achoices\u5b57\u6bb5\")\n                continue\n                \n            delta = chunk.choices&#91;0].delta\n            msg = delta.content if delta else None\n            \n            # \u8c03\u8bd5\u8f93\u51fa2\uff1a\u663e\u793a\u6d88\u606f\u5185\u5bb9\u7c7b\u578b\n            logger.debug(f\"&#91;Chunk {chunk_counter}] \u6d88\u606f\u7c7b\u578b: {type(msg)}, \u5185\u5bb9\u9884\u89c8: {str(msg)&#91;:50]}...\")\n            \n            if msg is None:\n                logger.info(f\"&#91;Chunk {chunk_counter}] \u6536\u5230\u7cfb\u7edf\u63a7\u5236\u6d88\u606f: {chunk}\")\n                continue\n\n            if first:\n                end = time.perf_counter()\n                logger.info(f\"llm Time to first chunk: {end-start}s\")\n                first = False\n\n            lastpos = 0\n            valid_chars = \",.!;:\uff0c\u3002\uff01\uff1f\uff1a\uff1b\"\n            \n            # \u5b89\u5168\u904d\u5386\u903b\u8f91\n            for i, char in enumerate(msg):\n                if char in valid_chars:\n                    result += msg&#91;lastpos:i+1]\n                    lastpos = i+1\n                    if len(result) &gt; 10:\n                        logger.info(f\"\u53d1\u9001\u5206\u6bb5: {result}\")\n                        nerfreal.put_msg_txt(result)\n                        result = \"\"\n            \n            result += msg&#91;lastpos:]\n\n        end = time.perf_counter()\n        logger.info(f\"llm Time to last chunk: {end-start}s\")\n        if result:\n            nerfreal.put_msg_txt(result)\n\n    except Exception as e:\n        logger.error(f\"LLM\u5904\u7406\u5f02\u5e38: {str(e)}\", exc_info=True)\n        nerfreal.put_msg_txt(\"\u670d\u52a1\u6682\u65f6\u4e0d\u53ef\u7528\uff0c\u8bf7\u7a0d\u540e\u518d\u8bd5\")\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u4f7f\u7528\u6548\u679c\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/ziline.top\/wp-content\/uploads\/2025\/04\/image-16-1024x634.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"634\" data-original=\"https:\/\/ziline.top\/wp-content\/uploads\/2025\/04\/image-16-1024x634.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-137\"  sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/div><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/ziline.top\/wp-content\/uploads\/2025\/04\/image-17.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"930\" height=\"527\" data-original=\"https:\/\/ziline.top\/wp-content\/uploads\/2025\/04\/image-17.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-138\"  sizes=\"auto, (max-width: 930px) 100vw, 930px\" \/><\/div><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00.pytorch\u548ccuda\u7248\u672c\u4e00\u5b9a\u8981\u5339\u914d\uff0cpython\u7248\u672c\u8981\u5927\u4e8e\u7b49\u4e8e3.9\u3002 \u4e8c.\u5728Live Talking [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-134","post","type-post","status-publish","format-standard","hentry","category-6"],"_links":{"self":[{"href":"https:\/\/ziline.top\/index.php\/wp-json\/wp\/v2\/posts\/134","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ziline.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ziline.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ziline.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ziline.top\/index.php\/wp-json\/wp\/v2\/comments?post=134"}],"version-history":[{"count":5,"href":"https:\/\/ziline.top\/index.php\/wp-json\/wp\/v2\/posts\/134\/revisions"}],"predecessor-version":[{"id":234,"href":"https:\/\/ziline.top\/index.php\/wp-json\/wp\/v2\/posts\/134\/revisions\/234"}],"wp:attachment":[{"href":"https:\/\/ziline.top\/index.php\/wp-json\/wp\/v2\/media?parent=134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ziline.top\/index.php\/wp-json\/wp\/v2\/categories?post=134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ziline.top\/index.php\/wp-json\/wp\/v2\/tags?post=134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}