Skip to content

Commit 22bea7a

Browse files
committed
Merge branch 'next'
2 parents 66c1e97 + 2900b9d commit 22bea7a

File tree

6 files changed

+278
-272
lines changed

6 files changed

+278
-272
lines changed

resources/index.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,12 +498,18 @@ <h1 class="card-title text-2xl justify-center mb-6">Voice Chat</h1>
498498
int16Array[i] = Math.max(-32768, Math.min(32767, audioData[i] * 32767));
499499
}
500500

501+
if (this.recordingMode) {
502+
this.websocket.send(JSON.stringify({ event: 'StartRecord' }));
503+
} else {
504+
this.websocket.send(JSON.stringify({ event: 'StartChat' }));
505+
}
506+
501507
this.websocket.send(int16Array.buffer);
502508
console.log('Sent VAD audio data to server, length:', int16Array.length);
503509

504510
// Send different end markers based on recording mode
505-
const endMarker = this.recordingMode ? "End:Recording" : "End:Normal";
506-
this.websocket.send(endMarker);
511+
const endMarker = this.recordingMode ? "Recording" : "Normal";
512+
this.websocket.send(JSON.stringify({ event: 'Submit' }));
507513
console.log('Sent end marker:', endMarker);
508514

509515
// Show sent end marker in debug mode

resources/index_zh.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,12 +498,18 @@ <h1 class="card-title text-2xl justify-center mb-6">语音聊天</h1>
498498
int16Array[i] = Math.max(-32768, Math.min(32767, audioData[i] * 32767));
499499
}
500500

501+
if (this.recordingMode) {
502+
this.websocket.send(JSON.stringify({ event: 'StartRecord' }));
503+
} else {
504+
this.websocket.send(JSON.stringify({ event: 'StartChat' }));
505+
}
506+
501507
this.websocket.send(int16Array.buffer);
502508
console.log('发送 VAD 音频数据到服务器,长度:', int16Array.length);
503509

504510
// 根据录制模式发送不同的结束标识
505-
const endMarker = this.recordingMode ? "End:Recording" : "End:Normal";
506-
this.websocket.send(endMarker);
511+
const endMarker = this.recordingMode ? "Recording" : "Normal";
512+
this.websocket.send(JSON.stringify({ event: 'Submit' }));
507513
console.log('发送结束标识:', endMarker);
508514

509515
// 在调试模式下显示发送的结束标识

src/ai/bailian/cosyvoice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ impl CosyVoiceTTS {
181181
log::debug!("Synthesis task finished");
182182
return Ok(None);
183183
} else if response.is_result_generated() {
184-
log::debug!("Result generated");
184+
log::trace!("Result generated:{text}");
185185
} else {
186186
return Err(anyhow::anyhow!("Synthesis error: {:?}", response));
187187
}

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ async fn routes(
7979
// .route("/", get(handler))
8080
.route("/ws/{id}", any(services::ws::ws_handler))
8181
.nest("/record", services::file::new_file_service("./record"))
82-
.layer(axum::Extension(Arc::new(services::ws::WsPool::new(
82+
.layer(axum::Extension(Arc::new(services::ws::WsSetting::new(
8383
hello_wav,
8484
config.config,
8585
tool_set,

src/protocol.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,28 @@ fn test_rmp_command() {
3636
_ => panic!("Unexpected command: {:?}", cmd),
3737
}
3838
}
39+
40+
#[derive(Debug, Serialize, Deserialize, Clone)]
41+
#[serde(tag = "event")]
42+
pub enum ClientCommand {
43+
StartRecord,
44+
StartChat,
45+
Submit,
46+
Text { input: String },
47+
}
48+
49+
#[test]
50+
fn test_rmp_client_command() {
51+
let cmd = ClientCommand::Text {
52+
input: "Hello".to_string(),
53+
};
54+
let data = serde_json::to_string(&cmd).unwrap();
55+
println!("Serialized data: {}", data);
56+
let cmd2: ClientCommand = serde_json::from_str(&data).unwrap();
57+
match cmd2 {
58+
ClientCommand::Text { input } => {
59+
assert_eq!(input, "Hello");
60+
}
61+
_ => panic!("Unexpected command: {:?}", cmd2),
62+
}
63+
}

0 commit comments

Comments
 (0)