aliyunasr

package
v0.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2026 License: None detected not legal advice Imports: 0 Imported by: 0

Documentation

Overview

Package aliyunasr implements flyto.TranscriptionProvider against Aliyun DashScope's async file-transcription API (录音文件识别, model paraformer-8k-v2) -- the cloud fallback for the self-hosted oMLX ASR box.

The wire protocol differs from the OpenAI-compatible path in three ways the provider absorbs so consumers see ZERO difference (same TranscriptionRequest in, same TranscriptionResponse out):

  1. ASYNC: DashScope takes a task submission and is polled until SUCCEEDED; Transcribe polls internally and returns once, preserving the synchronous contract (callers already budget minutes-level deadlines).
  2. URL INPUT: the task API only accepts a publicly reachable file URL, not bytes. Transcribe spools the audio stream to a temp file (size needed for the upload; disk, never memory), PUTs it to an OSS bucket with a V1 header signature, hands the task a time-limited signed GET URL, and best-effort deletes the object afterwards (a bucket lifecycle rule is the real cleaner).
  3. CHANNEL SPLIT: channel_id=[0,1] makes DashScope transcribe each stereo channel independently -- the physical channel IS the speaker, so channel 0 maps to req.LeftSpeaker and channel 1 to req.RightSpeaker, and the per-channel sentences are merged into one segment timeline (begin_time ascending, milliseconds converted to the contract's seconds).

Chat is NOT supported: Stream fails loud (transcription-only provider), mirroring how consumers type-assert optional capabilities.

aliyunasr 包对阿里云 DashScope 异步录音文件识别 API (paraformer-8k-v2) 实现 flyto.TranscriptionProvider -- 自托管 oMLX ASR 的云端备选. 线协议与 OpenAI 兼容路径的三个差异全部在 provider 内吸收, 消费者零感知 (同请求进, 同响应出): 1. 异步: 提交任务 + 内部轮询到 SUCCEEDED 一次性返回, 保持同步语义 (调用方 本来就按分钟级预算 deadline). 2. URL 输入: 任务只收公网 URL, 先落临时盘 (要长度; 走盘不走内存), V1 头签名 PUT 进 OSS, 给任务限时签名 GET URL, 完成后 尽力删除 (真正的清理靠 bucket 生命周期规则). 3. 声道分轨: channel_id=[0,1] 让左右声道各出一路独立转写 -- 物理声道即说话人, 0 -> LeftSpeaker, 1 -> RightSpeaker, 两路 sentences 按 begin_time 合并成统一时间线 (毫秒转秒). 不支持 chat: Stream fail-loud (纯转写 provider).

Index

Constants

View Source
const DefaultBaseURL = "https://dashscope.aliyuncs.com/api/v1"

DefaultBaseURL is the public DashScope API root; a workspace-scoped deployment (maas.aliyuncs.com host) overrides it via Config.BaseURL.

DefaultBaseURL 是公共 DashScope API 根; 业务空间专属部署 (maas.aliyuncs.com host) 经 Config.BaseURL 覆盖.

View Source
const ModelParaformer8kV2 = "paraformer-8k-v2"

ModelParaformer8kV2 is the 8k telephony-tuned file-transcription model this provider is validated against (the only entry in Models()).

ModelParaformer8kV2 是本 provider 实测过的 8k 电话音质录音识别模型 (Models() 唯一条目).

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	APIKey     string
	BaseURL    string
	OSS        OSSConfig
	HTTPClient *http.Client
	// contains filtered or unexported fields
}

Config configures the provider. APIKey is the DashScope key (required at use); BaseURL empty -> DefaultBaseURL; HTTPClient nil -> a 5-minute-timeout client (individual polls are short; the long wait lives in the poll LOOP bounded by ctx, not in any single request).

Config 配置 provider. APIKey 是 DashScope key (使用时必填); BaseURL 空 -> DefaultBaseURL; HTTPClient nil -> 5 分钟超时 client (单次轮询很短; 长等待在 ctx 界定的轮询循环里, 不在单个请求上).

type OSSConfig

type OSSConfig struct {
	Endpoint        string
	Bucket          string
	AccessKeyID     string
	AccessKeySecret string
}

OSSConfig locates the staging bucket used to hand DashScope a URL. Endpoint is the BUCKET base URL (virtual-host style, e.g. https://flytocall-audio.oss-cn-shanghai.aliyuncs.com); Bucket is the bucket name used in the V1 signature resource string. Empty credentials are allowed at construction and fail loud at Transcribe -- an instance can be registered before the operator provisions the sub-account key.

OSSConfig 定位中转 bucket. Endpoint 是 BUCKET 级 base URL (虚拟主机式); Bucket 是 V1 签名资源串里的桶名. 凭据允许构造期为空, Transcribe 时 fail loud -- 实例可以先注册, 子账号 key 后配.

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider implements flyto.ModelProvider (Stream fails loud) and flyto.TranscriptionProvider (the real capability).

Provider 实现 flyto.ModelProvider (Stream fail-loud) 与 flyto.TranscriptionProvider (真能力).

func New

func New(cfg Config) *Provider

New constructs the provider. 构造 provider.

func (*Provider) Models

func (p *Provider) Models(ctx context.Context) ([]flyto.ModelInfo, error)

Models implements flyto.ModelProvider with the static validated catalog. Models 返回静态实测目录.

func (*Provider) Name

func (p *Provider) Name() string

Name implements flyto.ModelProvider. 实现 flyto.ModelProvider.

func (*Provider) Stream

func (p *Provider) Stream(ctx context.Context, req *flyto.Request) (<-chan flyto.Event, error)

Stream implements flyto.ModelProvider by failing loud: this is a transcription-only provider, chat routing to it is a configuration error.

Stream 以 fail-loud 实现 flyto.ModelProvider: 纯转写 provider, chat 路由到 这里是配置错误.

func (*Provider) Transcribe

Transcribe implements flyto.TranscriptionProvider: spool -> OSS PUT -> submit task -> poll -> fetch result -> map channels to speakers. Blocks until done; budget the ctx in minutes for long recordings.

Transcribe 实现 flyto.TranscriptionProvider: 落盘 -> OSS PUT -> 提任务 -> 轮询 -> 取结果 -> 声道映射说话人. 阻塞到完成; 长录音按分钟级预算 ctx.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL