Windows 环境下 Golang 与 Vosk-API 语音识别开发环境搭建指南

一、前置准备工作

1、[安装Golang][https://go.dev/doc/install\]

2、安装window gcc环境。

​ 使用msys2来进行安装

  • 安装MinGW-w64 工具链

    cmd 复制代码
    pacman -S mingw-w64-x86_64-toolchain
  • 配置环境变量

  • 验证环境变量是否成功

cmd 复制代码
C:\Users\admin>gcc --version
gcc (Rev5, Built by MSYS2 project) 15.1.0
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

上面说明已经安装成功。

二、拉取vosk-api的相关依赖

1、克隆vosk-api的相关代码

cmd 复制代码
git clone https://github.com/alphacep/vosk-api
cd vosk-api/go/example
# 把代码切换到tagv0.3.45上
git checkout v0.3.45

2、下载模型文件

cmd 复制代码
https://alphacephei.com/vosk/models/vosk-model-small-en-us-0.15.zip
// 下载完成后把模型文件复制到vosk-api/go/example,并且改名为model

3、下载vosk-api

cmd 复制代码
https://github.com/alphacep/vosk-api/releases/download/v0.3.45/vosk-win64-0.3.45.zip
将文件拷贝到D:\\source\\vosk目录下,然后解压

4、设置环境变量

cmd 复制代码
set VOSK_PATH=D:\\source\\vosk\\vosk-win64-0.3.45
set LD_LIBRARY_PATH=D:\\source\\vosk\\vosk-win64-0.3.45
set CGO_CPPFLAGS=-I D:\\source\\vosk\\vosk-win64-0.3.45
set CGO_LDFLAGS=-L D:\\source\\vosk\\vosk-win64-0.3.45  -lvosk -lwinpthread -lgcc_s -static-libstdc++ -static-libgcc 
# 需要设置该变量,不然会报 exit status 0xc0000135
set PATH=%PATH%;D:\source\vosk\vosk-win64-0.3.45

5、进行到vosk-api/go/example目录

把这个位置的文件,复制到当前目录。 .../.../python/example/test.wav

此时目录中文件及文件夹为:

cmd 复制代码
D:\source\vosk-api\go\example>dir /b
doc.go
model
README.md
test.wav
test_simple.go

运行程序:

cmd 复制代码
D:\source\vosk-api\go\example>go run . -f test.wav
LOG (VoskAPI:ReadDataFiles():model.cc:213) Decoding params beam=10 max-active=3000 lattice-beam=2
LOG (VoskAPI:ReadDataFiles():model.cc:216) Silence phones 1:2:3:4:5:6:7:8:9:10
LOG (VoskAPI:RemoveOrphanNodes():nnet-nnet.cc:948) Removed 0 orphan nodes.
LOG (VoskAPI:RemoveOrphanComponents():nnet-nnet.cc:847) Removing 0 orphan components.
LOG (VoskAPI:ReadDataFiles():model.cc:248) Loading i-vector extractor from model/ivector/final.ie
LOG (VoskAPI:ComputeDerivedVars():ivector-extractor.cc:183) Computing derived variables for iVector extractor
LOG (VoskAPI:ComputeDerivedVars():ivector-extractor.cc:204) Done.
LOG (VoskAPI:ReadDataFiles():model.cc:282) Loading HCL and G from model/graph/HCLr.fst model/graph/Gr.fst
LOG (VoskAPI:ReadDataFiles():model.cc:308) Loading winfo model/graph/phones/word_boundary.int
{
  "result" : [{
      "conf" : 1.000000,
      "end" : 1.110000,
      "start" : 0.840000,
      "word" : "one"
    }, {
      "conf" : 1.000000,
      "end" : 1.530000,
      "start" : 1.110000,
      "word" : "zero"
    }, {
      "conf" : 1.000000,
      "end" : 1.920000,
      "start" : 1.530000,
      "word" : "zero"
    }, {
      "conf" : 1.000000,
      "end" : 2.310000,
      "start" : 1.920000,
      "word" : "zero"
    }, {
      "conf" : 1.000000,
      "end" : 2.610000,
      "start" : 2.310000,
      "word" : "one"
    }],
  "text" : "one zero zero zero one"
}
{
  "result" : [{
      "conf" : 0.590374,
      "end" : 4.110000,
      "start" : 3.930000,
      "word" : "nah"
    }, {
      "conf" : 0.712806,
      "end" : 4.290000,
      "start" : 4.110000,
      "word" : "no"
    }, {
      "conf" : 0.719885,
      "end" : 4.560000,
      "start" : 4.290000,
      "word" : "to"
    }, {
      "conf" : 0.488564,
      "end" : 4.620000,
      "start" : 4.560000,
      "word" : "i"
    }, {
      "conf" : 0.763203,
      "end" : 4.980000,
      "start" : 4.620000,
      "word" : "know"
    }],
  "text" : "nah no to i know"
}
zero one eight zero three

运行成功,则说明环境搭建成功。

相关推荐
雨中散步撒哈拉39 分钟前
17、做中学 | 初三下期 Golang文件操作
开发语言·后端·golang
利刃大大2 小时前
【c++中间件】语音识别SDK && 二次封装
开发语言·c++·中间件·语音识别
apocelipes2 小时前
利用泛型编写更安全的Golang代码
golang·泛型编程
w***74408 小时前
SQL Server2022版详细安装教程(Windows)
windows
IT逆夜15 小时前
实现Yum本地仓库自动同步的完整方案(CentOS 7)
linux·运维·windows
v***598315 小时前
DeepSeek API 调用 - Spring Boot 实现
windows·spring boot·后端
s***45317 小时前
Linux 下安装 Golang环境
linux·运维·golang
q***25117 小时前
Windows操作系统部署Tomcat详细讲解
java·windows·tomcat
b***653218 小时前
GO 快速升级Go版本
开发语言·redis·golang