Skip to content

Commit 8379baf

Browse files
authored
Merge pull request #56 from TencentCloudBase/dev
Dev
2 parents 2fddb71 + 7c82638 commit 8379baf

File tree

13 files changed

+295
-43
lines changed

13 files changed

+295
-43
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
## [1.12.0](https://github.com/TencentCloudBase/cloudbase-agent-ui/compare/v1.11.0...v1.12.0) (2025-05-06)
6+
7+
8+
### Features
9+
10+
* 增加倍速控制 ([99690d9](https://github.com/TencentCloudBase/cloudbase-agent-ui/commit/99690d97673423ba99e28b772962e300ce450dea))
11+
12+
13+
### Bug Fixes
14+
15+
* fix doc ([72c6a53](https://github.com/TencentCloudBase/cloudbase-agent-ui/commit/72c6a53d226cf6426da4569be21d4bc77bba0827))
16+
517
## [1.11.0](https://github.com/TencentCloudBase/cloudbase-agent-ui/compare/v1.10.1...v1.11.0) (2025-04-27)
618

719

Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 2 additions & 0 deletions
Loading

apps/miniprogram-agent-ui/miniprogram/components/agent-ui/index.js

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ Component({
125125
frameSize: 50,
126126
},
127127
voiceRecognizing: false,
128+
speedList: [2, 1.5, 1.25, 1, 0.75],
128129
},
129130
attached: async function () {
130131
const chatMode = this.data.chatMode;
@@ -1912,15 +1913,20 @@ Component({
19121913
if (audioContext.recordId === botRecordId) {
19131914
// 是则直接播放
19141915
audioContext.playStatus = 2;
1916+
audioContext.showSpeedList = false;
1917+
// audioContext.currentSpeed = 1.25;
19151918
this.setData({
19161919
audioContext: audioContext,
19171920
});
1921+
audioContext.context.playbackRate = audioContext.currentSpeed;
19181922
audioContext.context.play();
19191923
} else {
19201924
// 需销毁当前的 audioContext TODO:, 先测试复用content, 直接更换src
19211925
audioContext.context.stop(); // 旧的停止
19221926
audioContext.recordId = botRecordId;
19231927
audioContext.playStatus = 1;
1928+
audioContext.showSpeedList = false;
1929+
audioContext.currentSpeed = 1.25;
19241930
this.setData({
19251931
audioContext: {
19261932
...audioContext,
@@ -1930,6 +1936,7 @@ Component({
19301936
if (audioUrl) {
19311937
audioContext.context.src = audioUrl;
19321938
audioContext.context.seek(0); // 播放进度拉回到0
1939+
audioContext.context.playbackRate = audioContext.currentSpeed;
19331940
audioContext.context.play();
19341941
this.setData({
19351942
audioContext: {
@@ -1952,11 +1959,20 @@ Component({
19521959
const audioContext = {
19531960
recordId: botRecordId,
19541961
playStatus: 1,
1962+
showSpeedList: false,
1963+
currentSpeed: 1.25,
19551964
};
1956-
const innerAudioContent = wx.createInnerAudioContext({
1965+
const innerAudioContext = wx.createInnerAudioContext({
19571966
useWebAudioImplement: false, // 是否使用 WebAudio 作为底层音频驱动,默认关闭。对于短音频、播放频繁的音频建议开启此选项,开启后将获得更优的性能表现。由于开启此选项后也会带来一定的内存增长,因此对于长音频建议关闭此选项
19581967
});
1959-
innerAudioContent.onEnded(() => {
1968+
try {
1969+
await wx.setInnerAudioOption({
1970+
obeyMuteSwitch: false, // 是否遵循系统静音开关,默认遵循
1971+
});
1972+
} catch (e) {
1973+
console.log("不遵循静音模式控制", e);
1974+
}
1975+
innerAudioContext.onEnded(() => {
19601976
// 音频自然播放至结束触发
19611977
this.setData({
19621978
audioContext: {
@@ -1965,13 +1981,14 @@ Component({
19651981
},
19661982
});
19671983
});
1968-
audioContext.context = innerAudioContent;
1984+
audioContext.context = innerAudioContext;
19691985
this.setData({
19701986
audioContext: audioContext,
19711987
});
19721988
const audioUrl = await this.fetchAudioUrlByContent(botRecordId, content);
19731989
if (audioUrl) {
19741990
audioContext.context.src = audioUrl;
1991+
audioContext.context.playbackRate = audioContext.currentSpeed; // 播放速率,范围 0.5~2.0,默认 1.0
19751992
audioContext.context.play();
19761993
this.setData({
19771994
audioContext: {
@@ -2006,14 +2023,38 @@ Component({
20062023
console.log("暂停异常");
20072024
}
20082025
},
2026+
toggleSpeedList(e) {
2027+
this.setData({
2028+
audioContext: {
2029+
...this.data.audioContext,
2030+
showSpeedList: !this.data.audioContext.showSpeedList,
2031+
},
2032+
});
2033+
},
2034+
chooseSpeed(e) {
2035+
const speed = e.currentTarget.dataset.speed;
2036+
console.log("choose speed", speed);
2037+
const audioContext = this.data.audioContext;
2038+
audioContext.showSpeedList = !this.data.audioContext.showSpeedList;
2039+
audioContext.currentSpeed = Number(speed);
2040+
audioContext.context.pause();
2041+
audioContext.context.playbackRate = audioContext.currentSpeed;
2042+
audioContext.context.play();
2043+
this.setData({
2044+
audioContext: {
2045+
...this.data.audioContext,
2046+
...audioContext,
2047+
},
2048+
});
2049+
},
20092050
// 触摸开始
20102051
handleTouchStart(e) {
2011-
if(this.data.chatStatus !== 0 || this.data.voiceRecognizing === true) {
2052+
if (this.data.chatStatus !== 0 || this.data.voiceRecognizing === true) {
20122053
wx.showToast({
20132054
title: "请等待对话完成",
20142055
icon: "error",
20152056
});
2016-
return
2057+
return;
20172058
}
20182059
console.log("touchstart e", e);
20192060
const { clientY } = e.touches[0];
@@ -2033,12 +2074,12 @@ Component({
20332074
},
20342075
// 触摸移动
20352076
handleTouchMove(e) {
2036-
if(this.data.chatStatus !== 0 || this.data.voiceRecognizing === true) {
2077+
if (this.data.chatStatus !== 0 || this.data.voiceRecognizing === true) {
20372078
wx.showToast({
20382079
title: "请等待对话完成",
20392080
icon: "error",
20402081
});
2041-
return
2082+
return;
20422083
}
20432084
console.log("touchMove");
20442085
if (!this.data.longPressTriggered) return;
@@ -2061,12 +2102,12 @@ Component({
20612102
},
20622103
// 触摸结束
20632104
handleTouchEnd(e) {
2064-
if(this.data.chatStatus !== 0 || this.data.voiceRecognizing === true) {
2105+
if (this.data.chatStatus !== 0 || this.data.voiceRecognizing === true) {
20652106
wx.showToast({
20662107
title: "请等待对话完成",
20672108
icon: "error",
20682109
});
2069-
return
2110+
return;
20702111
}
20712112
console.log("touchEnd e", e);
20722113
clearTimeout(this.data.longPressTimer);

apps/miniprogram-agent-ui/miniprogram/components/agent-ui/index.wxml

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,33 @@
148148
<markdownPreview markdown="{{item.content||''}}"></markdownPreview>
149149
<!-- 下面的按钮 -->
150150
<view style="display: flex; gap: 10px;justify-content: flex;" wx:if="{{!item.hiddenBtnGround}}">
151-
<image wx:if="{{item.error}}" mode="widthFix" bind:tap="showErrorMsg" src='./imgs/error-circle.svg' style="width: 36rpx; height: 36rpx;" data-content="{{item.error}}" data-reqid="{{item.reqId}}"/>
152-
<image mode="widthFix" bind:tap="copyChatRecord" src='./imgs/copy.svg' style="width: 36rpx; height: 36rpx;" data-content="{{item.content}}" />
151+
<image wx:if="{{item.error}}" mode="widthFix" bind:tap="showErrorMsg" src='./imgs/error-circle.svg' class="tool_btn" data-content="{{item.error}}" data-reqid="{{item.reqId}}"/>
152+
<image mode="widthFix" bind:tap="copyChatRecord" src='./imgs/copy.svg' class="tool_btn" data-content="{{item.content}}" />
153153
<block wx:if="{{!item.error}}">
154154
<button class="share_btn" open-type="share">
155-
<image mode="widthFix" src='./imgs/share.svg' style="width: 36rpx; height: 36rpx;vertical-align: top;" bind:tap="share" />
155+
<image mode="widthFix" src='./imgs/share.svg' class="tool_btn" style="vertical-align: top;" bind:tap="share" />
156156
</button>
157157
<block wx:if="{{chatMode=== 'bot'}}">
158-
<image mode="widthFix" bind:tap="openFeedback" data-feedbackType="upvote" data-feedbackRecordId="{{item.record_id}}" src='./imgs/thumb-up.svg' style="width: 36rpx; height: 36rpx;" />
159-
<image mode="widthFix" bind:tap="openFeedback" data-feedbackType="downvote" data-feedbackRecordId="{{item.record_id}}" src='./imgs/thumb-down.svg' style="width: 36rpx; height: 36rpx;" />
160-
<image wx:if="{{audioContext.recordId !== item.record_id || audioContext.playStatus === 0}}" mode="widthFix" bind:tap="handlePlayAudio" data-content="{{item.content}}" data-recordId="{{item.record_id}}" src='./imgs/play.svg' style="width: 36rpx; height: 36rpx;" />
161-
<image wx:elif="{{audioContext.playStatus === 1}}" mode="widthFix" src='./imgs/loading.svg' style="width: 36rpx; height: 36rpx;" />
162-
<image wx:else mode="widthFix" bind:tap="handlePauseAudio" data-recordId="{{item.record_id}}" src='./imgs/pause.svg' style="width: 36rpx; height: 36rpx;" />
158+
<image mode="widthFix" bind:tap="openFeedback" data-feedbackType="upvote" data-feedbackRecordId="{{item.record_id}}" src='./imgs/thumb-up.svg' class="tool_btn" />
159+
<image mode="widthFix" bind:tap="openFeedback" data-feedbackType="downvote" data-feedbackRecordId="{{item.record_id}}" src='./imgs/thumb-down.svg' class="tool_btn" />
160+
<image wx:if="{{audioContext.recordId !== item.record_id || audioContext.playStatus === 0}}" mode="widthFix" bind:tap="handlePlayAudio" data-content="{{item.content}}" data-recordId="{{item.record_id}}" src='./imgs/sound.svg' class="tool_btn" />
161+
<image wx:elif="{{audioContext.playStatus === 1}}" mode="widthFix" src='./imgs/loading.svg' class="tool_btn" />
162+
<view wx:else class="playing_btn">
163+
<image style="width: 36rpx;height: 36rpx;" mode="widthFix" bind:tap="handlePauseAudio" data-recordId="{{item.record_id}}" src='./imgs/pause.svg' />
164+
<image style="width: 30rpx;height: 30rpx" src="./imgs/playing.svg" mode="widthFix"/>
165+
<!-- 倍速切换按钮 -->
166+
<view class="speed-switch" bindtap="toggleSpeedList" data-recordId="{{item.record_id}}">
167+
168+
<text class="speed-label">{{audioContext.currentSpeed || '1'}}</text>X
169+
</view>
170+
<!-- 倍速弹窗 -->
171+
<view wx:if="{{audioContext.showSpeedList && audioContext.recordId === item.record_id}}" class="speed-popup">
172+
<view wx:for="{{speedList}}" wx:key="item" class="speed-option" bindtap="chooseSpeed" data-speed="{{item}}" data-recordId="{{item.record_id}}">
173+
<text>{{item}}X</text>
174+
<image wx:if="{{audioContext.currentSpeed === item}}" src="./imgs/check.svg" style="width: 24rpx;height: 24rpx;margin-left:8rpx;" />
175+
</view>
176+
</view>
177+
</view>
163178
</block>
164179
</block>
165180
</view>

apps/miniprogram-agent-ui/miniprogram/components/agent-ui/index.wxss

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@
104104
.share_btn {
105105
background-color: #fff;
106106
margin: 0px !important;
107-
padding: 0px !important;
108-
width: 36rpx !important;
109-
height: 36rpx;
107+
padding: 0rpx !important;
108+
width: 64rpx !important;
109+
height: 64rpx;
110110
}
111111

112112
.avatar {
@@ -671,4 +671,65 @@
671671
background-color: rgb(249, 251, 255);
672672
filter: brightness(95%);
673673
transition: filter 0.4s;
674+
}
675+
676+
.tool_btn {
677+
width: 36rpx;
678+
height: 36rpx;
679+
padding: 10rpx;
680+
border: 1rpx solid #cfcdcd;
681+
border-radius: 14rpx;
682+
/* box-sizing: content-box; */
683+
}
684+
685+
.playing_btn {
686+
height: 36rpx;
687+
padding: 10rpx;
688+
border: 1rpx solid #cfcdcd;
689+
border-radius: 14rpx;
690+
display: flex;
691+
align-items: center;
692+
gap: 10rpx;
693+
position: relative;
694+
}
695+
696+
.speed-switch {
697+
display: flex;
698+
align-items: center;
699+
margin-left: 0rpx;
700+
padding: 4rpx 12rpx;
701+
border-radius: 20rpx;
702+
/* background: #f5f5f7; */
703+
font-size: 26rpx;
704+
color: #222;
705+
cursor: pointer;
706+
}
707+
708+
.speed-label {
709+
margin-left: 6rpx;
710+
}
711+
712+
.speed-popup {
713+
position: absolute;
714+
bottom: 48rpx;
715+
right: 0;
716+
background: #fff;
717+
border-radius: 12rpx;
718+
box-shadow: 0 4rpx 16rpx rgba(0,0,0,0.08);
719+
z-index: 99;
720+
padding: 8rpx 0;
721+
min-width: 80rpx;
722+
}
723+
724+
.speed-option {
725+
padding: 16rpx 32rpx;
726+
font-size: 28rpx;
727+
color: #222;
728+
display: flex;
729+
align-items: center;
730+
justify-content: flex-start;
731+
}
732+
733+
.speed-option:active {
734+
background: #f0f0f0;
674735
}
Lines changed: 1 addition & 0 deletions
Loading

components/agent-ui/imgs/sound.svg

Lines changed: 2 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)