TJC.Cyclops.Speech
2026.4.29.2
dotnet add package TJC.Cyclops.Speech --version 2026.4.29.2
NuGet\Install-Package TJC.Cyclops.Speech -Version 2026.4.29.2
<PackageReference Include="TJC.Cyclops.Speech" Version="2026.4.29.2" />
<PackageVersion Include="TJC.Cyclops.Speech" Version="2026.4.29.2" />
<PackageReference Include="TJC.Cyclops.Speech" />
paket add TJC.Cyclops.Speech --version 2026.4.29.2
#r "nuget: TJC.Cyclops.Speech, 2026.4.29.2"
#:package TJC.Cyclops.Speech@2026.4.29.2
#addin nuget:?package=TJC.Cyclops.Speech&version=2026.4.29.2
#tool nuget:?package=TJC.Cyclops.Speech&version=2026.4.29.2
🎤 Cyclops.Speech
📝 项目概述
Cyclops.Speech 是 Cyclops.Framework 框架中的语音处理专家,为您的应用程序提供强大的语音识别、语音合成、语音分析等功能! 🚀
我们精心设计的组件集成了多种语音服务API,并提供统一的接口,支持本地处理和云服务两种模式,适用于语音交互、内容转换和音频分析等应用场景。无论是构建智能语音助手,还是实现语音转文字功能,Cyclops.Speech都能为您提供出色的支持。
✨ 为什么选择 Cyclops.Speech?
- 多模式支持:支持本地处理和云服务两种模式
- 多种服务集成:集成了Azure Speech、百度语音、讯飞语音等多种云服务
- 功能丰富:提供语音识别、语音合成、语音分析等完整功能
- 易于集成:与.NET依赖注入系统无缝集成
- 高性能:优化的音频处理和语音识别性能
- 灵活性:支持实时处理和批量处理两种模式
🎯 核心功能模块
🎤 语音识别(Speech-to-Text)
- 实时识别:实时语音识别,支持流式处理
- 文件转录:音频文件的批量转录
- 多语言支持:支持多种语言和方言
- 方言识别:支持各种地方方言的识别
- 说话人分离:自动识别和分离不同说话人
🔊 语音合成(Text-to-Speech)
- 文本转语音:将文本转换为自然流畅的语音
- 多音色选择:支持多种语音音色
- 参数调节:语速和音调的精细调节
- 情感合成:支持带情感的语音合成
- SSML支持:支持语音合成标记语言,实现更丰富的语音效果
📊 语音分析
- 特征提取:提取语音的各种特征参数
- 情绪识别:识别说话人的情绪状态
- 质量评估:评估语音质量和清晰度
- 说话人识别:识别和验证说话人身份
- 噪声处理:检测和过滤背景噪声
🎵 音频处理
- 格式转换:在不同音频格式之间转换
- 剪辑合并:音频的剪辑和多段音频的合并
- 降噪增强:降低噪声,增强语音清晰度
- 音频压缩:压缩音频文件大小
🔌 服务集成
- 本地模型:支持本地语音处理模型
- 云服务集成:集成Azure Speech、百度语音、讯飞语音等云服务
- 自动切换:根据网络和性能自动切换服务
- 离线模式:支持无网络环境下的离线处理
🛠️ 技术栈
- .NET 8.0:基础开发框架,利用最新的.NET特性
- NAudio:专业的音频处理库,提供音频捕获和处理能力
- ML.NET:机器学习库,用于本地语音处理模型
- Cyclops.Common:框架核心公共组件
- Cyclops.HttpClient:增强的HTTP客户端,用于与云服务API交互
📦 环境依赖
- .NET 8.0 SDK 或更高版本
- 可选:云服务API密钥:用于云服务模式,如Azure Speech、百度语音等
- 可选:音频设备:用于实时语音处理和录音
- 支持的平台:Windows、Linux、macOS
- IDE推荐:Visual Studio 2022、Visual Studio Code
🚀 安装配置
🔍 安装方式
NuGet包管理器
Install-Package Cyclops.Speech
.NET CLI
dotnet add package Cyclops.Speech
PackageReference
<PackageReference Include="Cyclops.Speech" Version="1.0.0" />
⚙️ 基本配置
配置文件设置
在appsettings.json中添加语音服务配置:
{
"Speech": {
"Azure": {
"ApiKey": "your_azure_api_key",
"Region": "your_azure_region"
},
"Baidu": {
"ApiKey": "your_baidu_api_key",
"SecretKey": "your_baidu_secret_key"
},
"Local": {
"ModelPath": "path_to_local_model"
}
}
}
依赖注入配置
在应用程序启动时进行配置:
// 在Program.cs或Startup.cs中
using Cyclops.Speech;
var builder = WebApplication.CreateBuilder(args);
// 添加Cyclops.Speech服务
builder.Services.AddCyclopsSpeech(options => {
// 基本配置
options.DefaultMode = SpeechMode.Cloud; // Cloud或Local
// 临时文件路径
options.TempFilePath = Path.Combine(AppContext.BaseDirectory, "Temp");
// 云服务配置
options.CloudServices = new Dictionary<SpeechProvider, CloudSpeechConfig> {
{
SpeechProvider.Azure,
new CloudSpeechConfig {
ApiKey = builder.Configuration["Speech:Azure:ApiKey"],
Region = builder.Configuration["Speech:Azure:Region"]
}
},
{
SpeechProvider.Baidu,
new CloudSpeechConfig {
ApiKey = builder.Configuration["Speech:Baidu:ApiKey"],
SecretKey = builder.Configuration["Speech:Baidu:SecretKey"]
}
}
};
// 本地模型配置
options.LocalModelPath = builder.Configuration["Speech:Local:ModelPath"];
// 音频配置
options.AudioFormat = AudioFormat.Wav;
options.SampleRate = 16000;
// 启用日志
options.EnableLogging = true;
});
// ...
🎯 配置建议
- 服务选择:根据应用需求和网络环境选择合适的服务模式(本地或云服务)
- API密钥安全:将API密钥存储在安全的配置管理系统中,避免硬编码
- 临时文件路径:确保临时文件路径有足够的存储空间
- 音频配置:根据实际需求调整音频格式和采样率
- 日志记录:在开发和测试环境建议启用日志,生产环境根据需要调整
📝 代码示例
🎤 语音识别示例
以下示例展示了如何使用 Cyclops.Speech 进行语音识别:
using Cyclops.Speech.Models;
using Cyclops.Speech.Services;
using Microsoft.Extensions.DependencyInjection;
// 获取语音识别服务
var speechRecognitionService = serviceProvider.GetRequiredService<ISpeechRecognitionService>();
// 识别音频文件
var recognitionResult = await speechRecognitionService.RecognizeFromFileAsync(
filePath: "sample.wav",
options: new SpeechRecognitionOptions {
Language = "zh-CN",
EnablePunctuation = true,
Provider = SpeechProvider.Azure
}
);
Console.WriteLine($"识别结果: {recognitionResult.Text}");
Console.WriteLine($"置信度: {recognitionResult.Confidence}");
// 实时语音识别
await using (var audioStream = new FileStream("sample.wav", FileMode.Open))
{
await speechRecognitionService.RecognizeFromStreamAsync(
audioStream: audioStream,
options: new SpeechRecognitionOptions {
Language = "zh-CN",
EnableContinuousRecognition = false
},
onPartialResult: partial => {
Console.WriteLine($"部分结果: {partial.Text}");
},
onFinalResult: final => {
Console.WriteLine($"最终结果: {final.Text}");
}
);
}
// 多语言识别
var multiLangResult = await speechRecognitionService.RecognizeFromFileAsync(
filePath: "multilingual.wav",
options: new SpeechRecognitionOptions {
AutoDetectLanguage = true,
EnableSpeakerDiarization = true
}
);
Console.WriteLine($"检测到的语言: {multiLangResult.DetectedLanguage}");
foreach (var segment in multiLangResult.Segments)
{
Console.WriteLine($"说话人 {segment.SpeakerId}: {segment.Text}");
}
🔊 语音合成示例
以下示例展示了如何使用 Cyclops.Speech 进行语音合成:
using Cyclops.Speech.Models;
using Cyclops.Speech.Services;
using Microsoft.Extensions.DependencyInjection;
// 获取语音合成服务
var speechSynthesisService = serviceProvider.GetRequiredService<ISpeechSynthesisService>();
// 基本文本转语音
var synthesisResult = await speechSynthesisService.SynthesizeAsync(
text: "您好,这是一个语音合成示例。Cyclops.Speech组件可以将文本转换为自然流畅的语音。",
options: new SpeechSynthesisOptions {
VoiceId = "zh-CN-XiaoxiaoNeural", // Azure语音ID
Speed = 1.0,
Pitch = 1.0
}
);
// 保存合成音频到文件
await using (var fileStream = new FileStream("synthesized_audio.wav", FileMode.Create))
{
await synthesisResult.AudioStream.CopyToAsync(fileStream);
}
Console.WriteLine($"语音合成完成,音频长度: {synthesisResult.AudioDuration.TotalSeconds} 秒");
// 使用SSML进行高级合成
var ssmlText = @"
<speak version='1.0' xmlns='http://www.w3.org/2001/10/synthesis' xml:lang='zh-CN'>
<voice name='zh-CN-YunxiNeural'>
<prosody rate='0.9'>这是一段语速较慢的文本。</prosody>
<break time='500ms'/>
<prosody rate='1.2'>这是一段语速较快的文本。</prosody>
<emphasis level='strong'>这是需要强调的内容。</emphasis>
</voice>
</speak>";
var ssmlResult = await speechSynthesisService.SynthesizeSsmlAsync(
ssml: ssmlText,
provider: SpeechProvider.Azure
);
// 直接播放合成音频
await speechSynthesisService.PlaySynthesizedAudioAsync(ssmlResult.AudioStream);
// 获取可用的语音列表
var availableVoices = await speechSynthesisService.GetAvailableVoicesAsync(
locale: "zh-CN",
provider: SpeechProvider.Azure
);
Console.WriteLine("可用的语音列表:");
foreach (var voice in availableVoices)
{
Console.WriteLine($"- {voice.Name} ({voice.Gender}) - {voice.Locale}");
}
📊 语音分析示例
以下示例展示了如何使用 Cyclops.Speech 进行语音分析:
using Cyclops.Speech.Models;
using Cyclops.Speech.Services;
using Microsoft.Extensions.DependencyInjection;
// 获取语音分析服务
var speechAnalysisService = serviceProvider.GetRequiredService<ISpeechAnalysisService>();
// 分析音频文件
var analysisResult = await speechAnalysisService.AnalyzeAudioAsync(
filePath: "sample.wav",
options: new SpeechAnalysisOptions {
AnalyzeEmotion = true,
AnalyzeQuality = true,
DetectSpeakers = true
}
);
// 输出分析结果
Console.WriteLine($"音频时长: {analysisResult.Duration.TotalSeconds} 秒");
Console.WriteLine($"采样率: {analysisResult.SampleRate} Hz");
Console.WriteLine($"声道数: {analysisResult.Channels}");
Console.WriteLine($"检测到的说话人数: {analysisResult.SpeakerCount}");
// 情绪分析结果
if (analysisResult.EmotionAnalysis != null)
{
Console.WriteLine("情绪分析结果:");
foreach (var emotion in analysisResult.EmotionAnalysis.DominantEmotions)
{
Console.WriteLine($"- {emotion.Type}: {emotion.Score:P2}");
}
}
// 语音质量分析
if (analysisResult.QualityAnalysis != null)
{
Console.WriteLine($"语音质量评分: {analysisResult.QualityAnalysis.OverallScore:P2}");
Console.WriteLine($"信噪比: {analysisResult.QualityAnalysis.SignalToNoiseRatio} dB");
Console.WriteLine($"噪声水平: {analysisResult.QualityAnalysis.NoiseLevel}");
}
// 实时语音分析
await speechAnalysisService.AnalyzeRealtimeAsync(
onSegmentAnalyzed: segment => {
Console.WriteLine($"语音段时长: {segment.Duration.TotalMilliseconds} ms");
Console.WriteLine($"语音段能量: {segment.Energy}");
if (segment.Emotion != null)
{
Console.WriteLine($"检测到的情绪: {segment.Emotion.Type} ({segment.Emotion.Score:P2})");
}
},
onSpeechDetected: () => {
Console.WriteLine("检测到语音开始");
},
onSpeechEnded: () => {
Console.WriteLine("检测到语音结束");
},
duration: TimeSpan.FromSeconds(10)
);
🎵 音频处理示例
以下示例展示了如何使用 Cyclops.Speech 进行音频处理:
using Cyclops.Speech.Services;
using Microsoft.Extensions.DependencyInjection;
// 获取音频处理服务
var audioProcessingService = serviceProvider.GetRequiredService<IAudioProcessingService>();
// 音频格式转换
await audioProcessingService.ConvertAudioFormatAsync(
inputFilePath: "input.mp3",
outputFilePath: "output.wav",
options: new AudioConversionOptions {
SampleRate = 16000,
Channels = 1,
BitsPerSample = 16
}
);
// 音频剪辑
await audioProcessingService.ClipAudioAsync(
inputFilePath: "long_audio.wav",
outputFilePath: "clipped_audio.wav",
startTime: TimeSpan.FromSeconds(10),
duration: TimeSpan.FromSeconds(30)
);
// 音频降噪
await audioProcessingService.RemoveNoiseAsync(
inputFilePath: "noisy_audio.wav",
outputFilePath: "denoised_audio.wav",
noiseReductionLevel: NoiseReductionLevel.Medium
);
// 音频合并
await audioProcessingService.MergeAudioFilesAsync(
inputFilePaths: new List<string> { "audio1.wav", "audio2.wav", "audio3.wav" },
outputFilePath: "merged_audio.wav"
);
// 调整音频参数
await audioProcessingService.AdjustAudioAsync(
inputFilePath: "original.wav",
outputFilePath: "adjusted.wav",
volume: 1.5f, // 增大50%音量
speed: 1.2f, // 加快20%速度
pitch: 1.1f // 提高10%音调
);
// 提取音频特征
var audioFeatures = await audioProcessingService.ExtractAudioFeaturesAsync("sample.wav");
Console.WriteLine("音频特征:");
Console.WriteLine($"平均能量: {audioFeatures.AverageEnergy}");
Console.WriteLine($"频谱中心: {audioFeatures.SpectralCentroid}");
Console.WriteLine($"过零率: {audioFeatures.ZeroCrossingRate}");
Console.WriteLine($"带宽: {audioFeatures.Bandwidth}");
## 🤝 贡献者
我们欢迎社区贡献!如果您有任何改进建议或功能需求,欢迎提交PR或Issue。
- **yswenli**:核心开发者
## 📋 版本信息
- **当前版本**:[](https://www.nuget.org/packages?q=TJC.Cyclops)
- **作者**:yswenli
- **描述**:企服版框架中语音处理组件
- **更新频率**:定期更新,持续改进
## 📄 许可证
保留所有权利
## 🎉 结语
Cyclops.Speech 致力于为您的应用程序提供强大、灵活的语音处理能力。我们相信,通过简化语音处理的复杂性,您可以更专注于业务逻辑的实现,构建出更智能、更交互性强的应用。
如果您有任何问题或建议,欢迎与我们联系!让我们一起构建更好的语音处理解决方案! 🚀
| 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. |
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.7)
- TJC.Cyclops.Common (>= 2026.4.29.2)
- TJC.Cyclops.Service (>= 2026.4.29.2)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on TJC.Cyclops.Speech:
| Package | Downloads |
|---|---|
|
TJC.Cyclops.Web.Core
企服版框架中api核心功能项目,基于aspnetcore集成di、jwt、swagger、codefirtst、支持多种常见数据库、nacos配置中心、统一接口回复参数、全局异常捕获、全局接口日志、防重放攻击、图形验证码、快捷上下文对象、上传下载、数据导入导出等功能 |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2026.4.29.2 | 95 | 4/29/2026 |
| 2026.4.29.1 | 115 | 4/29/2026 |
| 2026.4.27.1 | 117 | 4/27/2026 |
| 2026.4.24.2 | 112 | 4/24/2026 |
| 2026.4.24.1 | 110 | 4/24/2026 |
| 2026.4.14.2 | 122 | 4/14/2026 |
| 2026.4.14.1 | 127 | 4/14/2026 |
| 2026.4.13.1 | 126 | 4/13/2026 |
| 2026.3.30.1 | 135 | 3/30/2026 |
| 2026.3.26.1 | 127 | 3/26/2026 |
| 2026.3.24.1 | 123 | 3/24/2026 |
| 2026.3.12.2 | 134 | 3/12/2026 |
| 2026.3.12.1 | 128 | 3/12/2026 |
| 2026.2.26.1 | 131 | 2/26/2026 |
| 2026.2.4.1 | 155 | 2/4/2026 |
| 2026.1.15.1 | 168 | 1/15/2026 |
| 2026.1.14.2 | 148 | 1/14/2026 |
| 2026.1.14.1 | 145 | 1/14/2026 |
| 2026.1.13.2 | 165 | 1/13/2026 |
| 2026.1.13.1 | 167 | 1/13/2026 |
语音转换工具类