chore: 完善从节点连接提示音

This commit is contained in:
Del Wang
2026-01-01 13:05:06 +08:00
parent ab872180fc
commit 118c34eb5c
4 changed files with 19 additions and 7 deletions
+1 -1
View File
@@ -2,7 +2,7 @@ build:
docker run --rm -v $(shell pwd):/app idootop/open-xiaoai-runtime:oh2p \
cargo build --target armv7-unknown-linux-gnueabihf --release
# 部署到小爱音箱(调试用)
# 部署到小爱音箱(调试用)
deploy:
dd if=target/armv7-unknown-linux-gnueabihf/release/stereo \
| sshpass -p open-xiaoai ssh -o HostKeyAlgorithms=+ssh-rsa root@192.168.31.153 "dd of=/data/stereo"
+9 -2
View File
@@ -13,14 +13,21 @@ pub async fn run_stereo() -> Result<()> {
return Ok(());
}
let mode = &args[1];
let mode = if args[1].to_lowercase() == "master" {
"主节点"
} else {
"从节点"
};
let role = if args[2].to_lowercase() == "left" {
ChannelRole::Left
} else {
ChannelRole::Right
};
if mode == "master" {
println!("🚗 当前为: {} {}", mode, role.to_string());
if mode == "主节点" {
run_master(role).await
} else {
run_slave(role).await
-2
View File
@@ -26,8 +26,6 @@ struct SlaveSession {
}
pub async fn run_master(master_role: ChannelRole) -> Result<()> {
println!("--- 主节点模式 ({}) ---", master_role.to_string());
// 0. 设置 ALSA 重定向
println!("🔥 启动中,请稍等...");
let _alsa_guard = AlsaRedirector::new()?;
+9 -2
View File
@@ -9,6 +9,7 @@ use crate::net::protocol::{AudioPacket, ChannelRole, ControlPacket};
use crate::utils::jitter_buffer::JitterBuffer;
use crate::utils::sync::{ClockSync, now_us};
use anyhow::{Result, anyhow};
use std::process::Command;
use std::sync::Arc;
use std::time::Duration;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
@@ -16,8 +17,6 @@ use tokio::sync::{Mutex, mpsc};
/// 运行从节点模式
pub async fn run_slave(role: ChannelRole) -> Result<()> {
println!("--- 从节点模式 ({}) ---", role.to_string());
loop {
match handle_connection(role.clone()).await {
Err(e) => {
@@ -134,6 +133,14 @@ async fn handle_connection(role: ChannelRole) -> Result<()> {
// 8. 播放主循环
println!("✅ 主节点已连接,音频串流中...");
let _ = Command::new("sh")
.arg("-c")
.arg(format!(
"/usr/sbin/tts_play.sh \"主节点已连接,{}\" >/dev/null 2>&1",
role.to_string()
))
.status();
let mut pcm_buf = vec![0i16; config.frame_size];
let mut last_seq: Option<u32> = None;
let mut last_packet_time = now_us();