6ef9e082a6
- 前端: VAD语音检测(@ricky0123/vad-web) + useVoiceInput双模式(流式WS/REST) - Gateway: VoiceStreamManager代理WS流式STT到voice-service - Voice-service: DashScope REST → Realtime WS → Whisper三级引擎 + ffmpeg转码 - 共享模块: pkg/audio(音频转换) + pkg/dashscope(ASR REST客户端) - 清理: 移除旧plugin-manager和pkg/plugins,完成插件→工具合并 - 文档: 完善gateway-api.md和voice-service.md语音API文档 - 工具: scripts/voice/ 语音转换脚本集 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"git.yeij.top/AskaEth/Cyrene/pkg/dashscope"
|
|
)
|
|
|
|
// DashScopeRESTSTT 使用 DashScope REST API 进行离线语音识别。
|
|
// 离线模型 (qwen3-asr-flash-2026-02-10) 通过 HTTP REST 端点进行转录,
|
|
// 无需 session 协商和 Server VAD,延迟更低,适合非实时场景。
|
|
type DashScopeRESTSTT struct {
|
|
model string
|
|
client *dashscope.RESTClient
|
|
}
|
|
|
|
// NewDashScopeRESTSTT 创建 DashScope REST STT 客户端。
|
|
func NewDashScopeRESTSTT(apiKey, model string) *DashScopeRESTSTT {
|
|
if model == "" {
|
|
model = "qwen3-asr-flash-2026-02-10"
|
|
}
|
|
return &DashScopeRESTSTT{
|
|
model: model,
|
|
client: dashscope.NewRESTClient(apiKey),
|
|
}
|
|
}
|
|
|
|
// IsAvailable 检查 API Key 是否已配置。
|
|
func (d *DashScopeRESTSTT) IsAvailable() bool {
|
|
return d.client.IsAvailable()
|
|
}
|
|
|
|
// Model 返回模型名。
|
|
func (d *DashScopeRESTSTT) Model() string { return d.model }
|
|
|
|
// Transcribe 使用 DashScope REST API 进行离线语音识别。
|
|
func (d *DashScopeRESTSTT) Transcribe(ctx context.Context, audioData []byte, format, language string) (string, error) {
|
|
if !d.IsAvailable() {
|
|
return "", fmt.Errorf("DashScope REST ASR API key 未配置")
|
|
}
|
|
return d.client.Transcribe(ctx, d.model, audioData, format, 16000, language)
|
|
}
|
|
|
|
// GetStatus 返回 REST STT 客户端的运行状态。
|
|
func (d *DashScopeRESTSTT) GetStatus() map[string]interface{} {
|
|
return map[string]interface{}{
|
|
"available": d.IsAvailable(),
|
|
"model": d.model,
|
|
"protocol": "rest",
|
|
}
|
|
}
|