https://geeknote.net/wulu
wulu
/assets/avatar-c195dbe387bf2d666eedca03bc60e64574323f2a.png
2023-05-20T12:44:21Z
wulu
https://geeknote.net/wulu
https://geeknote.net/wulu/posts/2333
2023-05-16T15:39:21Z
2023-05-20T12:44:21Z
指定 Whisper 输出为简体中文
<blockquote>
<p><a href="https://github.com/openai/whisper">Whisper</a>是OpenAI推出的一种开源语音识别模型,能够自动识别多种语言,将音频转换文字。Whisper由python实现,同时拥有丰富的社区支持。除了原始的Whisper之外,还有一些相关的项目,有移植到 C/C++的<a href="https://github.com/ggerganov/whisper.cpp">whisper.cpp</a>和能使用GPU加速的<a href="https://github.com/guillaumekln/faster-whisper">faster-whisper</a>。如果你不懂编程或者不熟悉命令行,也有也有很多开发者开发了图形界面,比如<a href="https://github.com/chidiwilliams/buzz">buzz</a>和<a href="https://github.com/Const-me/Whisper">Const-me/Whisper</a>等。</p>
</blockquote>
<p><a href="https://github.com/openai/whisper">Whisper</a> 支持直接输出srt格式的字幕文件。我最近用 <a href="https://github.com/openai/whisper">Whisper</a> 生成字幕文件,再配合ChatGPT 使用<a href="https://github.com/gnehs/subtitle-translator-electron">subtitle-translator-electron</a> 翻译字幕,整体效果还是很好的。但是 <a href="https://github.com/openai/whisper">Whisper</a>也有问题,就是<a href="https://github.com/openai/whisper">Whisper</a> 使用<code>--language</code>来指定语言,但无论是简体中文还是繁体中文,对于的代码都是<code>zh</code>。很多情况下,使用<a href="https://github.com/openai/whisper">Whisper</a> 生成字幕文件,设置参数<code>--language zh</code>,会生成繁体中文的字幕文件。</p>
<h2>
<a id="%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88" href="#%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88" class="anchor"></a>解决方案</h2>
<p>在网上终于查到解决方案,分享给大家。 在 Whisper 的<a href="https://github.com/openai/whisper/discussions/277">讨论区</a>中,<a href="https://github.com/jongwook">@jongwook</a> 提出:</p>
<ol>
<li>使用 <code>--initial_prompt"</code> 参数,用简体中文输入 <code>"以下是普通话的句子。"</code> 就能生成简体中文字幕。</li>
<li>以此类推,用繁体中文输入 <code>"以下是普通話的句子。"</code> 就能得到繁体字幕。</li>
</ol>
<pre class="highlight"><code>$ whisper --language Chinese --model large audio.wav
[00:00.000 --> 00:08.000] 如果他们使用航空的方式运输货物在某些航线上可能要花几天的时间才能卸货和通关
$ whisper --language Chinese --model large audio.wav --initial_prompt "以下是普通話的句子。" # traditional
[00:00.000 --> 00:08.000] 如果他們使用航空的方式運輸貨物,在某些航線上可能要花幾天的時間才能卸貨和通關。
$ whisper --language Chinese --model large audio.wav --initial_prompt "以下是普通话的句子。" # simplified
[00:00.000 --> 00:08.000] 如果他们使用航空的方式运输货物,在某些航线上可能要花几天的时间才能卸货和通关。
</code></pre>
<p>另外,有关 <code>--initial_prompt</code> 参数,可在 <a href="https://platform.openai.com/docs/guides/speech-to-text/prompting">openai的文档</a> 查看更多。其中也提到 "有些语言可以用不同的方式书写,比如简体或繁体中文。模型可能默认不会使用你想要的转录写作风格。你可以通过使用你偏好的写作风格的提示来改善这一点。"。</p>
Whisper是OpenAI推出的一种开源语音识别模型,能够自动识别多种语言,将音频转换文字。Whisper由python实现,同时拥有丰富的社区支持。除了原始的Whisper之外,还有一些相...
wulu
https://geeknote.net/wulu