Skip to content

Commit ec619e9

Browse files
fix: WavStreamPlayer (#298)
* fix: fix ChatV3Message Type and ws no voice in mobile * chore: Publish release/20250811-08d3be * chore: Publish release/20250811-31920c
1 parent 3068887 commit ec619e9

File tree

5 files changed

+70
-2
lines changed

5 files changed

+70
-2
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@coze/api",
5+
"comment": "fix ChatV3Message Type and ws no voice in mobile",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@coze/api",
10+
"email": "[email protected]"
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@coze/api",
5+
"comment": "Publish release/20250811-31920c",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@coze/api",
10+
"email": "[email protected]"
11+
}

packages/coze-js/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@coze/api",
3-
"version": "1.3.5",
3+
"version": "1.3.6",
44
"description": "Official Coze Node.js SDK for seamless AI integration into your applications | 扣子官方 Node.js SDK,助您轻松集成 AI 能力到应用中",
55
"keywords": [
66
"coze",
@@ -116,4 +116,4 @@
116116
"agora-rtc-sdk-ng": "$agora-rtc-sdk-ng"
117117
}
118118
}
119-
}
119+
}

packages/coze-js/src/resources/chat/chat.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,19 @@ export interface ChatV3Message {
710710
* Message type.
711711
*/
712712
type: MessageType;
713+
714+
/**
715+
* The ID of the section that contains this message.
716+
*/
717+
section_id: string;
718+
719+
/**
720+
* Chain of Thought (CoT) reasoning content from the model.
721+
* This field contains the step-by-step reasoning process showing how the model
722+
* breaks down complex problems into multiple simple steps to derive the final answer.
723+
* Only returned when the model supports deep thinking and the agent has enabled deep thinking.
724+
*/
725+
reasoning_content: string;
713726
}
714727

715728
export interface ToolCallType {

packages/coze-js/src/ws-tools/wavtools/lib/wav_stream_player.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { StreamProcessorSrc } from './worklets/stream_processor';
22
import LocalLoopback from './local-loopback';
33
import { decodeAlaw, decodeUlaw } from './codecs/g711';
4+
import { isMobile } from '../../utils';
45

56
/**
67
* Audio format types supported by WavStreamPlayer
@@ -60,6 +61,38 @@ export class WavStreamPlayer {
6061

6162
// Initialize volume (0 = muted, 1 = full volume)
6263
this.volume = volume;
64+
65+
// 在构造函数中就开始准备音频解锁,这样用户交互时就能立即解锁
66+
if (isMobile()) {
67+
this.prepareAudioUnlock();
68+
}
69+
}
70+
71+
/**
72+
* 预先准备音频解锁,在构造函数中调用
73+
* 这样当用户交互时就能立即解锁音频
74+
* @private
75+
*/
76+
private prepareAudioUnlock(): void {
77+
// 立即开始监听交互事件,但不等待
78+
const silentSound = document.createElement('audio');
79+
silentSound.setAttribute('src', 'data:audio/mp3;base64,//MkxAAHiAICWABElBeKPL/RANb2w+yiT1g/gTok//lP/W/l3h8QO/OCdCqCW2Cw//MkxAQHkAIWUAhEmAQXWUOFW2dxPu//9mr60ElY5sseQ+xxesmHKtZr7bsqqX2L//MkxAgFwAYiQAhEAC2hq22d3///9FTV6tA36JdgBJoOGgc+7qvqej5EPomQ+RMn/QmSACAv7mcADf//MkxBQHAAYi8AhEAO193vt9KGOq+6qcT7hhfN5FTInmwk8RkqKImTM55pRQHQSq//MkxBsGkgoIAABHhTACIJLf99nVI///yuW1uBqWfEu7CgNPWGpUadBmZ////4sL//MkxCMHMAH9iABEmAsKioqKigsLCwtVTEFNRTMuOTkuNVVVVVVVVVVVVVVVVVVV//MkxCkECAUYCAAAAFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV');
80+
silentSound.volume = 0.001;
81+
82+
const pageEvents = ['touchstart', 'touchend', 'mousedown', 'keydown'];
83+
const unlockAudio = async () => {
84+
try {
85+
await silentSound.play();
86+
pageEvents.forEach(event => {
87+
document.removeEventListener(event, unlockAudio);
88+
});
89+
} catch (e) {
90+
console.warn('[WavStreamPlayer] Audio context unlock failed', e);
91+
}
92+
}
93+
pageEvents.forEach(event => {
94+
document.addEventListener(event, unlockAudio);
95+
});
6396
}
6497

6598
/**

0 commit comments

Comments
 (0)