<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>语音转文字 &#8211; 编码无悔 /  Intent &amp; Focused</title>
	<atom:link href="https://www.codelast.com/tag/%E8%AF%AD%E9%9F%B3%E8%BD%AC%E6%96%87%E5%AD%97/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.codelast.com</link>
	<description>最优化之路</description>
	<lastBuildDate>Wed, 17 Sep 2025 14:29:50 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>[原创] 用Whisper.cpp在本地(离线)把mp3音频转成中文</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e7%94%a8whisper-cpp%e5%9c%a8%e6%9c%ac%e5%9c%b0%e7%a6%bb%e7%ba%bf%e6%8a%8amp3%e9%9f%b3%e9%a2%91%e8%bd%ac%e6%88%90%e4%b8%ad%e6%96%87/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e7%94%a8whisper-cpp%e5%9c%a8%e6%9c%ac%e5%9c%b0%e7%a6%bb%e7%ba%bf%e6%8a%8amp3%e9%9f%b3%e9%a2%91%e8%bd%ac%e6%88%90%e4%b8%ad%e6%96%87/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Wed, 17 Sep 2025 14:29:50 +0000</pubDate>
				<category><![CDATA[AI]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[ASR]]></category>
		<category><![CDATA[mp3转中文]]></category>
		<category><![CDATA[OpenAI]]></category>
		<category><![CDATA[whisper.cpp]]></category>
		<category><![CDATA[Whisper模型]]></category>
		<category><![CDATA[语音识别]]></category>
		<category><![CDATA[语音转文字]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=14183</guid>

					<description><![CDATA[<p>如果你有把mp3音频转成中文文本、并且不想调用任何云端API的需求，那么本文提供了一个可行的方案。<br />
OS：Ubuntu 20.04 LTS（MacOS类似可用）<br />
<span id="more-14183"></span></p>
<div style="text-align: center;">
	<img decoding="async" alt="audio to text" src="https://www.codelast.com/wp-content/uploads/2025/09/audio_to_text.png" style="width: 600px; height: 528px;" /></div>
<p>
我们首先要知道几个背景知识：<br />
<span style="color:#ff0000;">➤</span> whisper.cpp 是一个开源的 C/C++ 实现，用于运行 OpenAI 的 Whisper 模型。Whisper 是一种先进的自动语音识别（Automatic Speech Recognition, ASR）神经网络模型，能够将音频转换为文本。它支持多种语言，识别效果精准，并且可以完全离线运行，无需互联网连接。这个项目特别适合嵌入到各种应用程序中，因为它是轻量级的实现，可以在 CPU 上高效运行。<br />
<span style="color: rgb(255, 0, 0);">➤</span>&#160;whisper.cpp-cli 是对 whisper.cpp 命令行工具的 Python 封装。<br />
<span style="color:#ff0000;">➤</span>&#160;OpenAI 的 Whisper 模型是一个先进的自动语音识别系统。它是基于 Transformer 架构的神经网络模型，主要用于将音频转换为文本。Whisper 由 OpenAI 开源开发，使用了大规模的多语言数据集进行训练（包括 68 万小时的音频数据，支持 98 种语言），因此具有出色的准确性和鲁棒性，能够处理多种口音、背景噪音和技术术语。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e7%94%a8whisper-cpp%e5%9c%a8%e6%9c%ac%e5%9c%b0%e7%a6%bb%e7%ba%bf%e6%8a%8amp3%e9%9f%b3%e9%a2%91%e8%bd%ac%e6%88%90%e4%b8%ad%e6%96%87/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<p>如果你有把mp3音频转成中文文本、并且不想调用任何云端API的需求，那么本文提供了一个可行的方案。<br />
OS：Ubuntu 20.04 LTS（MacOS类似可用）<br />
<span id="more-14183"></span></p>
<div style="text-align: center;">
	<img decoding="async" alt="audio to text" src="https://www.codelast.com/wp-content/uploads/2025/09/audio_to_text.png" style="width: 600px; height: 528px;" /></div>
<p>
我们首先要知道几个背景知识：<br />
<span style="color:#ff0000;">➤</span> whisper.cpp 是一个开源的 C/C++ 实现，用于运行 OpenAI 的 Whisper 模型。Whisper 是一种先进的自动语音识别（Automatic Speech Recognition, ASR）神经网络模型，能够将音频转换为文本。它支持多种语言，识别效果精准，并且可以完全离线运行，无需互联网连接。这个项目特别适合嵌入到各种应用程序中，因为它是轻量级的实现，可以在 CPU 上高效运行。<br />
<span style="color: rgb(255, 0, 0);">➤</span>&nbsp;whisper.cpp-cli 是对 whisper.cpp 命令行工具的 Python 封装。<br />
<span style="color:#ff0000;">➤</span>&nbsp;OpenAI 的 Whisper 模型是一个先进的自动语音识别系统。它是基于 Transformer 架构的神经网络模型，主要用于将音频转换为文本。Whisper 由 OpenAI 开源开发，使用了大规模的多语言数据集进行训练（包括 68 万小时的音频数据，支持 98 种语言），因此具有出色的准确性和鲁棒性，能够处理多种口音、背景噪音和技术术语。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
因此，我们需要安装的是 <a href="https://github.com/charliermarsh/whisper.cpp-cli" target="_blank">whisper.cpp-cli</a>，并且要下载好 Whisper 模型文件，这样就能使用 whisper.cpp-cli 来调用Whisper模型文件进行语音识别了。<br />
为了不影响系统里安装的软件，我们通常都会用micromamba、uv之类的Python包管理器创建一个新的env（环境），然后在里面再安装其他的Python包。这里我们用uv，你也可以用其他的包管理器来创建env。</p>
<blockquote>
<p>
		mkdir whisper<br />
		cd whisper<br />
		uv venv . --python 3.8&nbsp; # 创建一个新环境<br />
		source&nbsp;bin/activate&nbsp; # 激活环境<br />
		uv pip install pip&nbsp; # 安装pip<br />
		pip install whisper.cpp-cli&nbsp; # 安装whisper.cpp-cli</p>
</blockquote>
<p>
这样我们就安装好了相关软件。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
把 mp3 转成 16 kHz 的 wav 文件：</p>
<blockquote>
<p>
		ffmpeg -y -i /home/codelast/st.mp3 -ar 16000 /home/codelast/st.wav</p>
</blockquote>
<p>注意，16 kHz 是Whisper要求的。</p>
<p>然后我们就可以开始做语音识别了：</p>
<blockquote>
<p>
		&nbsp;whisper-cpp -m ../whisper.cpp/download/x-ggml-model.zh.bin -f /home/codelast/st.wav -l zh --output-txt</p>
</blockquote>
<p>这个命令的参数：<br />
-m：指定使用 x-ggml-model.zh.bin 这个模型来做语音识别（模型文件要提前从 Hugging Face 上下载好）<br />
-f：指定输入文件，对 st.wav 这个音频文件进行语音识别<br />
-l：指定输出语言为中文<br />
--output-txt：直接输出txt文本。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
输出内容示例如下：</p>
<blockquote>
<div>
		whisper_init_from_file_with_params_no_state: loading model from &#39;../whisper.cpp/download/x-ggml-model.zh.bin&#39;</div>
<div>
		whisper_model_load: loading model</div>
<div>
		whisper_model_load: n_vocab&nbsp; &nbsp; &nbsp; &nbsp;= 51865</div>
<div>
		whisper_model_load: n_audio_ctx&nbsp; &nbsp;= 1500</div>
<div>
		whisper_model_load: n_audio_state = 768</div>
<div>
		whisper_model_load: n_audio_head&nbsp; = 12</div>
<div>
		whisper_model_load: n_audio_layer = 12</div>
<div>
		whisper_model_load: n_text_ctx&nbsp; &nbsp; = 448</div>
<div>
		whisper_model_load: n_text_state&nbsp; = 768</div>
<div>
		whisper_model_load: n_text_head&nbsp; &nbsp;= 12</div>
<div>
		whisper_model_load: n_text_layer&nbsp; = 12</div>
<div>
		whisper_model_load: n_mels&nbsp; &nbsp; &nbsp; &nbsp; = 80</div>
<div>
		whisper_model_load: ftype&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 1</div>
<div>
		whisper_model_load: qntvr&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 0</div>
<div>
		whisper_model_load: type&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 3 (small)</div>
<div>
		whisper_model_load: adding 1608 extra tokens</div>
<div>
		whisper_model_load: n_langs&nbsp; &nbsp; &nbsp; &nbsp;= 99</div>
<div>
		whisper_model_load:&nbsp; &nbsp; &nbsp; CPU total size =&nbsp; &nbsp;487.01 MB</div>
<div>
		whisper_model_load: model size&nbsp; &nbsp; =&nbsp; 487.01 MB</div>
<div>
		whisper_init_state: kv self size&nbsp; =&nbsp; &nbsp;49.55 MB</div>
<div>
		whisper_init_state: kv cross size =&nbsp; &nbsp;55.30 MB</div>
<div>
		whisper_init_state: compute buffer (conv)&nbsp; &nbsp;=&nbsp; &nbsp;22.54 MB</div>
<div>
		&nbsp;whisper_init_state: compute buffer (encode) =&nbsp; 2&nbsp;80.20 MB</div>
<div>
		whisper_init_state: compute buffer (cross)&nbsp; =&nbsp; &nbsp; 6.31 MB</div>
<div>
		whisper_init_state: compute buffer (decode) =&nbsp; &nbsp;97.40 MB</div>
<div>
		&nbsp;</div>
<div>
		system_info: n_threads = 4 / 8 | AVX = 1 | AVX2 = 1 | AVX512 = 0 | FMA = 1 | NEON = 0 | ARM_FMA = 0 | METAL = 0 | F16C = 1 | FP16_VA = 0 | WASM_SIMD = 0 | BLAS = 0 | SSE3 = 1 | SSSE3 = 1 | VSX = 0 | CUDA = 0 | COREML = 0 | OPENVINO = 0</div>
<div>
		&nbsp;</div>
<div>
		main: processing &#39;/home/codelast/st.wav&#39; (23957094 samples, 1497.3 sec), 4 threads, 1 processors, 5 beams + best of 5, lang = zh, task = transcribe, timestamps = 1 ...</div>
<div>
		&nbsp;</div>
<div>
		&nbsp;</div>
<div>
		[00:00:00.000 --&gt; 00:00:19.040]&nbsp; 这里是识别文字第一句</div>
<div>
		[00:00:19.040 --&gt; 00:00:40.280]&nbsp; 这里是识别文字第二句<br />
		......</div>
</blockquote>
<div>
	<br />
	可以看到，输出的内容是带有时间轴标识的。<br />
	细看会发现，Whisper输出的中文有时会有错别字，我们可以用AI进一步纠错，想怎么处理你就可以随意发挥了。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
	转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
	感谢关注我的微信公众号（微信扫一扫）：<br />
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
	以及我的微信视频号：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
		<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" /></p>
<div>
		&nbsp;</div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e7%94%a8whisper-cpp%e5%9c%a8%e6%9c%ac%e5%9c%b0%e7%a6%bb%e7%ba%bf%e6%8a%8amp3%e9%9f%b3%e9%a2%91%e8%bd%ac%e6%88%90%e4%b8%ad%e6%96%87/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
