LuBan.Speech
2026.7.17.1
dotnet add package LuBan.Speech --version 2026.7.17.1
NuGet\Install-Package LuBan.Speech -Version 2026.7.17.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LuBan.Speech" Version="2026.7.17.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LuBan.Speech" Version="2026.7.17.1" />
<PackageReference Include="LuBan.Speech" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add LuBan.Speech --version 2026.7.17.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: LuBan.Speech, 2026.7.17.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package LuBan.Speech@2026.7.17.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=LuBan.Speech&version=2026.7.17.1
#tool nuget:?package=LuBan.Speech&version=2026.7.17.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
English | 中文
LuBan.Speech
作者: yswenli | 联系邮箱: yswenli@outlook.com | 代码仓库: https://github.com/yswenli/luban-framework
语音识别极简集成 —— 语音识别 API 一行代码接入,音频流转文字如此简单。
Related Projects: LuBan.Framework | LuBan.Service | LuBan.Common | LuBan.Web.Core
为什么选择 LuBan.Speech?
语音识别功能需求越来越多,但对接各大语音平台 API 总是繁琐的:OAuth 令牌管理、音频格式转换、Base64 编码、结果解析……
LuBan.Speech 提供了统一的语音识别接口:
ISpeechService统一接口,支持扩展多种语音引擎- 工厂模式创建服务实例,配置驱动
- 内置语音识别实现(
语音识别服务SpeechService) - 自动管理 OAuth 2.0 令牌获取
- 支持 PCM 等音频格式的流式识别
- 单例模式,全局复用
快速预览
// 从配置创建(自动读取配置文件中的 SpeechConfig)
var speechService = SpeechFactory.Create();
// 或手动指定配置
var speechService = SpeechFactory.Create(new SpeechConfig
{
SpeechType = EnumSpeechType.Baidu,
ClientId = "your-baidu-app-id",
ClientSecret = "your-baidu-app-secret"
});
// 语音识别
using var audioStream = File.OpenRead("speech.pcm");
var result = await speechService.RecognitionAsync(audioStream, "pcm");
Console.WriteLine($"识别结果: {result}");
技术栈
| 组件 | 说明 |
|---|---|
| LuBan.Service | 服务基类 |
| LuBan.Common | 基础工具库 |
| .NET | 8.0 |
安装
dotnet add package LuBan.Speech
功能概览
| 功能模块 | 核心类 | 说明 |
|---|---|---|
| 统一接口 | ISpeechService |
SetConfig / GetToken / RecognitionAsync |
| 工厂 | SpeechFactory |
根据配置创建语音服务实例 |
| 语音识别服务实现 | 语音识别服务SpeechService |
语音识别(单例,OAuth 令牌) |
| 配置 | SpeechConfig |
语音类型、ClientId、ClientSecret |
| 类型枚举 | EnumSpeechType |
语音识别服务 等 |
详细用法
配置
{
"SpeechConfig": {
"SpeechType": 0,
"ClientId": "your-baidu-app-id",
"ClientSecret": "your-baidu-app-secret"
}
}
获取令牌
var speechService = SpeechFactory.Create();
var token = await speechService.GetToken();
// token 可用于前端直接调用语音识别 API
音频识别
var speechService = SpeechFactory.Create();
// PCM 格式识别
using var pcmStream = File.OpenRead("audio.pcm");
var result = await speechService.RecognitionAsync(pcmStream, "pcm");
// 默认 PCM 格式
using var stream = GetAudioStream();
var result = await speechService.RecognitionAsync(stream);
语音识别 API 参数说明
内部调用语音识别 API 时的默认参数:
| 参数 | 值 | 说明 |
|---|---|---|
| format | pcm | 音频格式 |
| rate | 16000 | 采样率 |
| channel | 1 | 单声道 |
| cuid | GUID | 设备唯一标识(自动生成) |
使用提示
语音识别服务SpeechService为单例模式(BaseService<语音识别服务SpeechService>),全局复用- 音频流需为 PCM 格式,16000Hz 采样率,单声道。其他格式需先转换
SpeechFactory.Create()无参版本从ConfigUtil.Read<SpeechConfig>()读取配置- 语音识别 API 对音频时长有限制(通常不超过 60 秒),长音频需分段处理
- 语音识别结果以逗号分隔的字符串返回(多个候选结果)
- 扩展新语音引擎只需实现
ISpeechService接口并在SpeechFactory中注册
许可证
Copyright (c) yswenli. All rights reserved.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- LuBan.Common (>= 2026.7.17.1)
- LuBan.Service (>= 2026.7.17.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.10)
- SqlSugarCore (>= 5.1.4.216)
- System.Security.Cryptography.Xml (>= 10.0.10)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on LuBan.Speech:
| Package | Downloads |
|---|---|
|
LuBan.Web.Core
LuBan Framework中api核心功能项目,基于aspnetcore集成di、jwt、swagger、codefirtst、支持多种常见数据库、nacos配置中心、统一接口回复参数、全局异常捕获、全局接口日志、防重放攻击、图形验证码、快捷上下文对象、上传下载、数据导入导出等功能 |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2026.7.17.1 | 0 | 7/17/2026 |
| 2026.7.13.2 | 119 | 7/13/2026 |
| 2026.7.13.1 | 119 | 7/13/2026 |
| 2026.7.12.2 | 147 | 7/12/2026 |
| 2026.7.12.1 | 149 | 7/12/2026 |
| 2026.7.11.2 | 126 | 7/11/2026 |
语音转换工具类