Skip to main content

Request

Enum Request 

Source
pub enum Request {
    Vad(AudioRequest),
    Asr(AudioRequest),
    Diar(AudioRequest),
    SourceSeparation(AudioRequest),
    Tts(Box<TtsRequest>),
    Align(Box<AlignRequest>),
    Json(String),
}
Expand description

一次任务请求。

对应 capi.cpp parse_task_request 读取的顶层 JSON 字段(text / language / audio / audio_path / options)。按任务种类区分变体, 每个变体携带自己的参数;序列化时统一展开为上述 JSON 形状。

任务种类本身由 crate::Model::create_task_session 的 task 参数决定, 变体只决定请求形状(音频型 / 文本型 / 原始 JSON)。TaskKind 到构造器的 推荐映射:

任务构造器
Vad / Asr / Diar / SourceSeparationvad / asr / diar / source_separation(音频型)
Tts(含 VoiceCloning/VoiceConversion/VoiceDesign 等文本型任务)tts(文本型,可带参考音频/风格)
AudioGeneration(音乐生成,如 YuE2:歌词 + style 选项)tts(文本型)或 json
Alignment(强制对齐:音频 + 文本 + 语言)align
Midi(音频转谱,如 SheetSage2:音频型,结果在产物字段)形状相同的任一音频型变体,或 json
SpeechToSpeech / Svc / SpeakerRecognition(音频型)形状相同的任一音频型变体,或 json
其他 / 形状特殊json(原始 JSON 透传)

音频型四个变体(Vad/Asr/Diar/SourceSeparation)序列化形状完全 相同,选用时以语义就近为准。

Variants§

§

Vad(AudioRequest)

语音活动检测:需音频输入,可配 threshold 等。

§

Asr(AudioRequest)

语音识别:需音频输入,流式时用 audio_chunk_seconds 控制窗口。

§

Diar(AudioRequest)

说话人分离:需音频输入。

§

SourceSeparation(AudioRequest)

音乐源分离(Demucs 等):需音频输入。

§

Tts(Box<TtsRequest>)

语音合成:需文本,可带说话人参考音频(声音克隆)。

用 Box 包裹以缩小枚举整体体积(TtsRequest 远大于其他变体)。

§

Align(Box<AlignRequest>)

强制对齐:需音频 + 待对齐文本 + 文本语言。

用 Box 包裹以缩小枚举整体体积。

§

Json(String)

原始 JSON 字符串透传(不经任何序列化改动)。

Implementations§

Source§

impl Request

Source

pub fn vad(audio: impl Into<AudioInput>) -> Self

VAD 请求:以音频输入构造。

Source

pub fn asr(audio: impl Into<AudioInput>) -> Self

ASR 请求:以音频输入构造。

Source

pub fn stream_asr() -> Self

流式 ASR 请求:仅含选项,无音频输入。

用于流式会话的 start / prepare(音频经 crate::Session::process_audio 逐块送入,无需 audio_path)。 例如:

use audio_cpp::Request;
let req = Request::stream_asr().option("language", "auto").option("audio_chunk_seconds", 3.0);
assert_eq!(req.to_json().unwrap(), r#"{"options":{"audio_chunk_seconds":3.0,"language":"auto"}}"#);
Source

pub fn stream() -> Self

👎Deprecated since 0.4.0:

请改用 Request::stream_asr(原名易被误用于 TTS 流式)

Request::stream_asr 的旧名(保留兼容,请用 stream_asr)。

Source

pub fn diar(audio: impl Into<AudioInput>) -> Self

说话人分离请求:以音频输入构造。

Source

pub fn source_separation(audio: impl Into<AudioInput>) -> Self

音乐源分离请求:以音频输入构造。

Source

pub fn tts(text: impl Into<String>) -> Self

TTS 请求:以待合成文本构造。

Source

pub fn align( audio: impl Into<AudioInput>, text: impl Into<String>, language: impl Into<String>, ) -> Self

强制对齐请求:以音频、待对齐文本、文本语言构造。

序列化为 {"audio_path"|"audio", "text", "language", "options?"}, 配 [TaskKind::Alignment] 会话使用,结果的逐词时间戳在 crate::TaskResult::word_timestamps。例如:

use audio_cpp::Request;
let req = Request::align("./speech.wav", "你好世界", "zh")
    .option("clamp_timestamps_to_audio", true);
let v: serde_json::Value = serde_json::from_str(&req.to_json().unwrap()).unwrap();
assert_eq!(v["text"], "你好世界");
assert_eq!(v["language"], "zh");
§语言代码(上游要求非空,不支持 "auto")
  • qwen3_forced_aligner:zh / en / yue / fr / de / it / ja / ko / pt / ru / es(11 语种,见上游 model_specs/qwen3_forced_aligner.json);错配不报错,只产出劣质时间戳。
  • mms_forced_aligner:nl(nld)/ en(eng)拉丁文本;非拉丁输入 直接拒绝(可用 text_normalization=pre_romanized 传调用方自备的 ASCII 罗马化文本)。权重为 CC-BY-NC-4.0,禁止分发。
Source

pub fn json(s: impl Into<String>) -> Self

原始 JSON 字符串透传(不经序列化改动,直接交给 C 边界)。

Source

pub fn option<V: Into<Value>>(self, key: impl Into<String>, value: V) -> Self

设置一个选项键值(等价于 JSON options 里的一个字段)。

注意:对 Request::Json 调用将被静默忽略(原始 JSON 不经序列化改动)。如需给透传 JSON 加选项,请直接改 JSON 字符串。

Source

pub fn options<K, V>(self, opts: impl IntoIterator<Item = (K, V)>) -> Self
where K: Into<String>, V: Into<Value>,

批量设置选项。对 Request::Json 调用将被静默忽略(见 Request::option)。

Source

pub fn reference(self, audio: impl Into<AudioInput>) -> Self

设置说话人参考音频(仅对 Request::Tts 有效,其余变体静默忽略)。

Source

pub fn reference_text(self, text: impl Into<String>) -> Self

设置参考音频的文本转写(仅对 Request::Tts 有效,其余变体静默忽略)。

Source

pub fn voice(self, voice: VoiceCondition) -> Self

设置说话人参考 / 风格条件(仅对 Request::Tts 有效,其余变体静默忽略)。

Source

pub fn language(self, language: impl Into<String>) -> Self

设置文本语言(仅对 Request::Tts 有效,其余变体静默忽略)。

Source

pub fn to_json(&self) -> Result<String, Error>

序列化为 JSON 字符串(传给底层 C ABI)。Request::Json 原样返回。

§Errors

当内部对象无法序列化为合法 JSON 时返回 Error::Json。

Trait Implementations§

Source§

impl Clone for Request

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Request

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl IntoRequest for Request

Source§

fn into_request(self) -> Result<Request, Error>

转换为请求对象。 Read more
Source§

impl IntoRequest for &Request

Source§

fn into_request(self) -> Result<Request, Error>

转换为请求对象。 Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.