Files
open-xiaoai/packages/client-v2/src/audio/config.rs
T

57 lines
1.3 KiB
Rust
Raw Normal View History

2026-01-02 13:04:19 +08:00
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
2026-01-02 09:59:29 +08:00
pub enum AudioScene {
Music,
Voice,
}
2026-01-02 13:04:19 +08:00
#[derive(Debug, Clone, Serialize, Deserialize)]
2026-01-02 09:59:29 +08:00
pub struct AudioConfig {
pub capture_device: String,
pub playback_device: String,
pub sample_rate: u32,
pub channels: u16,
2026-01-02 17:23:24 +08:00
pub frame_size: usize,
2026-01-02 09:59:29 +08:00
pub audio_scene: AudioScene,
pub bitrate: i32,
2026-01-02 17:23:24 +08:00
pub vbr: bool,
pub fec: bool,
2026-01-02 09:59:29 +08:00
}
impl AudioConfig {
2026-01-02 17:23:24 +08:00
pub fn voice_16k() -> Self {
2026-01-02 09:59:29 +08:00
Self {
2026-01-02 17:23:24 +08:00
capture_device: "plug:Capture".to_string(),
playback_device: "plug:default".to_string(),
sample_rate: 16_000,
channels: 1,
frame_size: 320, // 20ms
audio_scene: AudioScene::Voice,
bitrate: 32_000,
vbr: true,
2026-01-04 15:06:55 +08:00
fec: false,
2026-01-02 09:59:29 +08:00
}
}
2026-01-02 17:23:24 +08:00
pub fn music_48k() -> Self {
2026-01-02 09:59:29 +08:00
Self {
2026-01-02 17:23:24 +08:00
capture_device: "plug:Capture".to_string(),
playback_device: "plug:default".to_string(),
sample_rate: 48_000,
channels: 2,
frame_size: 960, // 20ms
audio_scene: AudioScene::Music,
2026-01-04 15:06:55 +08:00
bitrate: 320_000,
2026-01-02 17:23:24 +08:00
vbr: true,
2026-01-04 15:06:55 +08:00
fec: false,
2026-01-02 09:59:29 +08:00
}
}
}
impl Default for AudioConfig {
fn default() -> Self {
2026-01-02 17:23:24 +08:00
Self::voice_16k()
2026-01-02 09:59:29 +08:00
}
}