{"id":20711,"date":"2025-02-09T23:41:33","date_gmt":"2025-02-09T15:41:33","guid":{"rendered":"https:\/\/www.aisharenet.com\/?p=20711"},"modified":"2025-07-21T04:16:28","modified_gmt":"2025-07-20T20:16:28","slug":"kokoro-webgpu","status":"publish","type":"post","link":"https:\/\/www.kdjingpai.com\/en\/kokoro-webgpu\/","title":{"rendered":"Kokoro WebGPU\uff1a\u6d4f\u89c8\u5668\u4e2d\u79bb\u7ebf\u8fd0\u884c\u7684\u6587\u672c\u8f6c\u8bed\u97f3\u670d\u52a1"},"content":{"rendered":"<p><a href=\"https:\/\/www.kdjingpai.com\/en\/kokoro\/\">Kokoro<\/a> WebGPU\u662fKokoro\u6587\u672c\u8f6c\u8bed\u97f3\uff08TTS\uff09\u6a21\u578b\u7684WebGPU\u7248\u672c\uff0c\u7531WebML Community\u5728Hugging Face\u5e73\u53f0\u4e0a\u63d0\u4f9b\u3002\u8be5\u9879\u76ee\u5229\u7528WebGPU\u6280\u672f\uff0c\u4f7f\u7528\u6237\u80fd\u591f\u5728\u6d4f\u89c8\u5668\u4e2d\u672c\u5730\u8fd0\u884c\u9ad8\u6548\u7684\u6587\u672c\u8f6c\u8bed\u97f3\u8f6c\u6362\u3002WebGPU\u662f\u4e00\u79cd\u73b0\u4ee3\u7684\u56fe\u5f62\u548c\u8ba1\u7b97API\uff0c\u80fd\u591f\u5728\u6d4f\u89c8\u5668\u4e2d\u5b9e\u73b0\u9ad8\u6027\u80fd\u7684\u8ba1\u7b97\u4efb\u52a1\u3002Kokoro WebGPU\u6a21\u578b\u65e8\u5728\u4e3a\u7528\u6237\u63d0\u4f9b\u5feb\u901f\u3001\u53ef\u9760\u7684\u6587\u672c\u8f6c\u8bed\u97f3\u670d\u52a1\uff0c\u9002\u7528\u4e8e\u5404\u79cd\u5e94\u7528\u573a\u666f\uff0c\u5982\u6709\u58f0\u4e66\u3001\u64ad\u5ba2\u3001\u6559\u80b2\u89c6\u9891\u7b49\u3002<\/p>\n<blockquote><p>Kokoro \u662f\u4e00\u4e2a\u62e5\u6709 8200 \u4e07\u53c2\u6570\u7684\u5f00\u6e90 TTS \u6a21\u578b\u3002\u5c3d\u7ba1\u5176\u67b6\u6784\u8f7b\u91cf\uff0c\u4f46\u5728\u8bed\u97f3\u5408\u6210\u8d28\u91cf\u4e0a\u53ef\u5ab2\u7f8e\u66f4\u5927\u578b\u7684\u6a21\u578b\uff0c\u540c\u65f6\u5728\u901f\u5ea6\u548c\u6210\u672c\u4e0a\u66f4\u5177\u4f18\u52bf\u3002Kokoro \u91c7\u7528 Apache 2.0 \u8bb8\u53ef\u8bc1\uff0c\u5141\u8bb8\u5728\u5404\u79cd\u73af\u5883\u4e2d\u81ea\u7531\u90e8\u7f72\uff0c\u65e0\u8bba\u662f\u751f\u4ea7\u73af\u5883\u8fd8\u662f\u4e2a\u4eba\u9879\u76ee\u3002<\/p><\/blockquote>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-20712\" title=\"Kokoro WebGPU\uff1a\u6d4f\u89c8\u5668\u672c\u5730\u8fd0\u884c\u7684\u6587\u672c\u8f6c\u8bed\u97f3\u670d\u52a1-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/02\/c1651c4ed119e9d.png\" alt=\"Kokoro WebGPU\uff1a\u6d4f\u89c8\u5668\u672c\u5730\u8fd0\u884c\u7684\u6587\u672c\u8f6c\u8bed\u97f3\u670d\u52a1-1\" width=\"1053\" height=\"753\" srcset=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/02\/c1651c4ed119e9d.png 1053w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/02\/c1651c4ed119e9d-768x549.png 768w\" sizes=\"auto, (max-width: 1053px) 100vw, 1053px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2>\u529f\u80fd\u5217\u8868<\/h2>\n<ul>\n<li><strong>\u9ad8\u6548\u6587\u672c\u8f6c\u8bed\u97f3<\/strong>\uff1a\u5229\u7528WebGPU\u6280\u672f\uff0c\u5b9e\u73b0\u9ad8\u6027\u80fd\u7684\u6587\u672c\u8f6c\u8bed\u97f3\u8f6c\u6362\u3002<\/li>\n<li><strong>\u6d4f\u89c8\u5668\u8fd0\u884c<\/strong>\uff1a\u65e0\u9700\u5b89\u88c5\u989d\u5916\u8f6f\u4ef6\uff0c\u76f4\u63a5\u5728\u6d4f\u89c8\u5668\u4e2d\u8fd0\u884c\u3002<\/li>\n<li><strong>\u591a\u8bed\u8a00\u652f\u6301<\/strong>\uff1a\u652f\u6301\u591a\u79cd\u8bed\u8a00\u7684\u6587\u672c\u8f6c\u8bed\u97f3\u8f6c\u6362\u3002<\/li>\n<li><strong>\u5b9e\u65f6\u54cd\u5e94<\/strong>\uff1a\u63d0\u4f9b\u5feb\u901f\u7684\u54cd\u5e94\u65f6\u95f4\uff0c\u9002\u5408\u5b9e\u65f6\u5e94\u7528\u3002<\/li>\n<li><strong>\u5f00\u6e90\u793e\u533a\u652f\u6301<\/strong>\uff1a\u7531WebML Community\u63d0\u4f9b\u652f\u6301\uff0c\u7528\u6237\u53ef\u4ee5\u53c2\u4e0e\u793e\u533a\u8ba8\u8bba\u548c\u5f00\u53d1\u3002<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2>\u4f7f\u7528\u5e2e\u52a9<\/h2>\n<h3>\u6d4f\u89c8\u5668\u8fd0\u884c\u7684\u6837\u672c\u4ee3\u7801<\/h3>\n<p>\u8981\u5728\u6d4f\u89c8\u5668\u4e2d\u4f7f\u7528 Kokoro\uff0c\u9996\u5148\u9700\u8981\u5b89\u88c5\u00a0<code>kokoro-js<\/code>\u00a0\u5e93\u3002<\/p>\n<pre><code>npm install kokoro-js\r\n<\/code><\/pre>\n<p>\u7136\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u751f\u6210\u8bed\u97f3\uff1a<\/p>\n<pre><code>import\u00a0{ KokoroTTS }\u00a0from\"kokoro-js\";\r\n\r\nconst\u00a0model_id =\u00a0\"onnx-community\/Kokoro-82M-v1.0-ONNX\";\r\nconst\u00a0tts =\u00a0await\u00a0KokoroTTS.from_pretrained(model_id, {\r\ndtype:\u00a0\"q8\",\u00a0\/\/ \u53ef\u9009\u503c: \"fp32\", \"fp16\", \"q8\", \"q4\", \"q4f16\"\r\ndevice:\u00a0\"wasm\",\u00a0\/\/ \u53ef\u9009\u503c: \"wasm\", \"webgpu\" (web) \u6216 \"cpu\" (node)\u3002\u5982\u679c\u4f7f\u7528 \"webgpu\"\uff0c\u5efa\u8bae\u4f7f\u7528 dtype=\"fp32\"\u3002\r\n});\r\n\r\nconst\u00a0text =\u00a0\"\u751f\u6d3b\u5c31\u50cf\u4e00\u76d2\u5de7\u514b\u529b\uff0c\u4f60\u6c38\u8fdc\u4e0d\u77e5\u9053\u4f60\u4f1a\u5f97\u5230\u4ec0\u4e48\u3002\";\r\nconst\u00a0audio =\u00a0await\u00a0tts.generate(text, {\r\n\/\/ \u4f7f\u7528 `tts.list_voices()` \u5217\u51fa\u6240\u6709\u53ef\u7528\u7684\u58f0\u97f3\r\nvoice:\u00a0\"af_heart\",\r\n});\r\naudio.save(\"audio.wav\");\r\n<\/code><\/pre>\n<p>\u4e0a\u8ff0\u4ee3\u7801\u5728\u6d4f\u89c8\u5668\u73af\u5883\u4e2d\u8fd0\u884c\uff0c\u5229\u7528 WebGPU \u6280\u672f\u5b9e\u73b0\u9ad8\u6548\u7684\u8bed\u97f3\u5408\u6210\u3002<\/p>\n<h3>Python \u4ee3\u7801<\/h3>\n<p>\u5728 Python \u73af\u5883\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u00a0<code>kokoro<\/code>\u00a0\u5e93\u8fdb\u884c\u8bed\u97f3\u5408\u6210\u3002<\/p>\n<pre><code># \u5b89\u88c5 kokoro \u548c soundfile\r\n!pip install kokoro&gt;=0.7.11\u00a0soundfile\r\n# \u5b89\u88c5 espeak-ng\uff0c\u7528\u4e8e\u82f1\u8bed OOD \u56de\u9000\u548c\u67d0\u4e9b\u975e\u82f1\u8bed\u8bed\u8a00\r\n!apt-get -qq -y install espeak-ng &gt; \/dev\/null\u00a02&gt;&amp;1\r\n\r\nfrom\u00a0kokoro\u00a0import\u00a0KPipeline\r\nfrom\u00a0IPython.display\u00a0import\u00a0display, Audio\r\nimport\u00a0soundfile\u00a0as\u00a0sf\r\n\r\n# \u521d\u59cb\u5316\u7ba1\u9053\r\npipeline = KPipeline(lang_code='a')\u00a0# 'a' \u8868\u793a\u7f8e\u5f0f\u82f1\u8bed\r\n\r\ntext =\u00a0'''\r\n\u5929\u7a7a\u7684\u989c\u8272\u50cf\u7535\u89c6\u673a\u8c03\u5230\u6ca1\u6709\u4fe1\u53f7\u7684\u9891\u9053\u3002\r\n\"\u8fd9\u4e0d\u50cf\u6211\u5728\u4f7f\u7528\uff0c\"\u51ef\u65af\u542c\u5230\u6709\u4eba\u8bf4\uff0c\u4ed6\u6324\u8fc7 Chat \u95e8\u53e3\u7684\u62e5\u6324\u4eba\u7fa4\u3002\"\u8fd9\u5c31\u50cf\u6211\u7684\u8eab\u4f53\u4ea7\u751f\u4e86\u5de8\u5927\u7684\u836f\u7269\u7f3a\u4e4f\u75c7\u3002\"\r\n\u90a3\u662f\u4e00\u4e2a\u5927\u90fd\u5e02\u7684\u58f0\u97f3\u548c\u7b11\u8bdd\u3002Chatsubo \u662f\u4e00\u4e2a\u4e3a\u4e13\u4e1a\u5916\u7c4d\u4eba\u58eb\u5f00\u7684\u9152\u5427\uff1b\u4f60\u53ef\u4ee5\u5728\u90a3\u559d\u4e0a\u4e00\u5468\uff0c\u5374\u542c\u4e0d\u5230\u4e24\u53e5\u65e5\u8bed\u3002\r\n'''\r\n\r\n# \u751f\u6210\u5e76\u4fdd\u5b58\u97f3\u9891\r\ngenerator = pipeline(\r\n\u00a0 \u00a0 text, voice='af_heart',\u00a0# \u66f4\u6539\u58f0\u97f3\r\n\u00a0 \u00a0 speed=1, split_pattern=r'\\n+'\r\n)\r\nfor\u00a0i, (gs, ps, audio)\u00a0in\u00a0enumerate(generator):\r\n\u00a0 \u00a0 print(i) \u00a0# \u7d22\u5f15\r\n\u00a0 \u00a0 print(gs)\u00a0# \u5b57\u7b26\r\n\u00a0 \u00a0 print(ps)\u00a0# \u97f3\u7d20\r\n\u00a0 \u00a0 display(Audio(data=audio, rate=24000, autoplay=i==0))\r\n\u00a0 \u00a0 sf.write(f'{i}.wav', audio,\u00a024000)\u00a0# \u4fdd\u5b58\u6bcf\u4e2a\u97f3\u9891\u6587\u4ef6\r\n<\/code><\/pre>\n<p>\u4e0a\u8ff0\u4ee3\u7801\u5728 Python \u73af\u5883\u4e2d\u8fd0\u884c\uff0c\u5229\u7528\u00a0<code>kokoro<\/code>\u00a0\u5e93\u5b9e\u73b0\u6587\u672c\u5230\u8bed\u97f3\u7684\u8f6c\u6362\u3002<\/p>\n<h3>\u6d4f\u89c8\u5668\u4e2d\u76f4\u63a5\u4f53\u9a8c<\/h3>\n<p>\u60a8\u53ef\u4ee5\u76f4\u63a5\u5728\u6d4f\u89c8\u5668\u4e2d\u4f53\u9a8c Kokoro TTS\uff0c\u65e0\u9700\u4efb\u4f55\u5b89\u88c5\u3002\u8bf7\u8bbf\u95ee\u4ee5\u4e0b\u94fe\u63a5\uff1a<\/p>\n<p>https:\/\/huggingface.co\/spaces\/webml-community\/kokoro-webgpu<\/p>\n<p>\u8bf7\u6ce8\u610f\uff0c\u8be5\u5e94\u7528\u7a0b\u5e8f\u7ea6\u6709 300 \u591a\u5146\u5b57\u8282\uff0c\u9700\u8981\u5b8c\u5168\u52a0\u8f7d\u5b8c\u6210\u540e\u624d\u80fd\u4f53\u9a8c\u3002\u7136\u800c\uff0c\u4f5c\u4e3a\u4e00\u4e2a\u5b8c\u5168\u5728\u6d4f\u89c8\u5668\u4e2d\u8fd0\u884c\u7684\u9ad8\u6548 TTS \u6a21\u578b\uff0c\u8fd9\u6837\u7684\u7b49\u5f85\u662f\u503c\u5f97\u7684\u3002<\/p>\n<h3>\u4e3b\u8981\u529f\u80fd\u64cd\u4f5c\u6d41\u7a0b<\/h3>\n<h4>\u6587\u672c\u8f6c\u8bed\u97f3<\/h4>\n<ol>\n<li><strong>\u8f93\u5165\u6587\u672c<\/strong>\uff1a\u5728\u8f93\u5165\u6846\u4e2d\u8f93\u5165\u9700\u8981\u8f6c\u6362\u4e3a\u8bed\u97f3\u7684\u6587\u672c\u3002<\/li>\n<li><strong>\u9009\u62e9\u8bed\u8a00<\/strong>\uff1a\u9009\u62e9\u9700\u8981\u8f6c\u6362\u7684\u8bed\u8a00\uff0c\u5982\u82f1\u8bed\u3001\u6cd5\u8bed\u3001\u65e5\u8bed\u7b49\u3002<\/li>\n<li><strong>\u8fd0\u884c\u6a21\u578b<\/strong>\uff1a\u70b9\u51fb\u8fd0\u884c\u6309\u94ae\uff0c\u6a21\u578b\u5c06\u8fdb\u884c\u6587\u672c\u8f6c\u8bed\u97f3\u8f6c\u6362\u3002<\/li>\n<li><strong>\u67e5\u770b\u7ed3\u679c<\/strong>\uff1a\u8bed\u97f3\u7ed3\u679c\u5c06\u663e\u793a\u5728\u9875\u9762\u4e0a\uff0c\u7528\u6237\u53ef\u4ee5\u64ad\u653e\u548c\u4e0b\u8f7d\u751f\u6210\u7684\u8bed\u97f3\u6587\u4ef6\u3002<\/li>\n<\/ol>\n<h3>\u7279\u8272\u529f\u80fd<\/h3>\n<ul>\n<li><strong>\u5b9e\u65f6\u8f6c\u6362<\/strong>\uff1aKokoro WebGPU\u5229\u7528WebGPU\u6280\u672f\uff0c\u5b9e\u73b0\u4e86\u5b9e\u65f6\u7684\u6587\u672c\u8f6c\u8bed\u97f3\u8f6c\u6362\uff0c\u9002\u5408\u9700\u8981\u5feb\u901f\u54cd\u5e94\u7684\u5e94\u7528\u573a\u666f\u3002<\/li>\n<li><strong>\u591a\u8bed\u8a00\u652f\u6301<\/strong>\uff1a\u652f\u6301\u591a\u79cd\u8bed\u8a00\u7684\u6587\u672c\u8f6c\u8bed\u97f3\u8f6c\u6362\uff0c\u7528\u6237\u53ef\u4ee5\u6839\u636e\u9700\u6c42\u9009\u62e9\u4e0d\u540c\u7684\u8bed\u8a00\u3002<\/li>\n<li><strong>\u793e\u533a\u652f\u6301<\/strong>\uff1a\u7531WebML Community\u63d0\u4f9b\u652f\u6301\uff0c\u7528\u6237\u53ef\u4ee5\u53c2\u4e0e\u793e\u533a\u8ba8\u8bba\uff0c\u83b7\u53d6\u6280\u672f\u652f\u6301\u548c\u66f4\u65b0\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Kokoro WebGPU\u662fKokoro\u6587\u672c\u8f6c\u8bed\u97f3\uff08TTS\uff09\u6a21\u578b\u7684WebGPU\u7248\u672c\uff0c\u7531WebML Community\u5728Hugging Face\u5e73\u53f0\u4e0a\u63d0\u4f9b\u3002\u8be5\u9879\u76ee\u5229\u7528WebGPU\u6280\u672f\uff0c\u4f7f\u7528\u6237\u80fd\u591f\u5728\u6d4f\u89c8\u5668\u4e2d\u672c\u5730\u8fd0\u884c\u9ad8\u6548\u7684\u6587\u672c\u8f6c\u8bed\u97f3\u8f6c\u6362\u3002WebG&#8230;<\/p>\n","protected":false},"author":1,"featured_media":32782,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,416,479],"tags":[230,215],"class_list":["post-20711","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tool","category-ai-audio","category-text-to-speech","tag-aikaiyuanxiangmu","tag-aiwenbenzhuanyuyin"],"_links":{"self":[{"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/posts\/20711","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/comments?post=20711"}],"version-history":[{"count":0,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/posts\/20711\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/media\/32782"}],"wp:attachment":[{"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/media?parent=20711"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/categories?post=20711"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/tags?post=20711"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}