Browse Source

音色添加音频试听

htc 1 day ago
parent
commit
d6b1e4324d
1 changed files with 125 additions and 24 deletions
  1. 125 24
      pagesRole/voice.vue

+ 125 - 24
pagesRole/voice.vue

@@ -1,18 +1,34 @@
 <template>
 	<view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
 		<cus-header title='音色'></cus-header>
+		<div class="top adfacjb" v-if="voice">
+			<div class="tl">
+				<image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/07/04/a09113ef-34fe-4105-bc4e-84ab7351ffc8.gif"></image>
+				<text>{{voice.name||''}}</text>
+			</div>
+			<div class="tr adfac">
+				<div class="tr_btn qx" @tap="cancel">取消</div>
+				<div class="tr_btn qr" @tap="confirm">确认</div>
+			</div>
+		</div>
 		<template v-if="list.length">
 			<div class="list">
 				<div class="item adfacjb" :class="{'active':index===idx}" v-for="(item,index) in list" :key="index" @tap="selectVoice(item,index)">
-					<div class="il">{{item.name}}</div>
-					<div class="ir" v-if="index===idx">已选择</div>
+					<div class="il adfac">
+						<image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/07/04/6a79f5d7-2d41-4405-97e2-e93876797ec8.png" v-if="item.sex==1"></image>
+						<image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/07/04/c4eaec06-7de9-4f1c-b76d-ead9a4a38373.png" v-else-if="item.sex==2"></image>
+						<text>{{item.name}}</text>
+					</div>
+					<div class="ir">
+						<image @tap.stop="playOnOff(0,item,index)" src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/07/04/fbfe67d5-a69b-4bb1-81a5-83d19403b88e.png" v-if="item.play"></image>
+						<image @tap.stop="playOnOff(1,item,index)" src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/07/04/9ef5fc85-05b2-4681-b37e-47cf843f5b6c.png" v-else></image>
+					</div>
 				</div>
 			</div>
 		</template>
 		<template v-else>
 			<page-empty :height="'calc(100vh - 160rpx)'"></page-empty>
 		</template>
-		<div class="zt_btn" @tap="confirm">确认选择</div>
 	</view>
 </template>
 
@@ -22,30 +38,73 @@
 		components:{pageEmpty},
 		data(){
 			return {
+				audioCtx: null,
 				idx:'',
 				list:[],
-				voice:null
+				voice:null,
 			}
 		},
 		onLoad() {
 			this.getModelVoiceList();
 		},
+		mounted() {
+			this.audioCtx = uni.createInnerAudioContext()	
+		},
 		methods:{
 			getModelVoiceList(){
-				this.$api.get(`/models/${'TTS_EdgeTTS'}/voices`).then(res=>{
+				this.$api.get(`/ttsVoice`,{
+					ttsModelId:'TTS_EdgeTTS',
+					page:1,
+					limit:-1
+				}).then(res=>{
 					if(res.data.code!==0) return this.$showToast(res.data.msg)
-					this.list = res.data.data;
+					this.list = res.data.data.list;
+					this.list.forEach((l,i)=>{
+						if(l.name.indexOf('男声')>-1) l.sex=1
+						else if(l.name.indexOf('女声')>-1) l.sex=2
+						this.$set(this.list[i],'play',false);
+					})
 				})
 			},
 			selectVoice(item,index){
 				this.voice = item;
 				this.idx = index;
 			},
+			playOnOff(type,item,index){
+				let idx = this.list.findIndex(l=>l.play);
+				if(idx!==index) {
+					this.audioCtx.pause();
+					this.audioCtx.src = '';
+				}
+				
+				this.voice = item;
+				this.audioCtx.src = item.voiceDemo;
+				this.list.forEach((l,i)=>{
+					this.$set(this.list[i],'play',false);
+				})
+				this.$set(this.list[index],'play',type);
+				uni.pageScrollTo({ scrollTop: 0, duration: 100});
+				
+				if(type==1) this.audioCtx.play();
+				else if(type===0) this.audioCtx.pause();
+			},
+			cancel(){
+				this.voice = null;
+				this.list.forEach((l,i)=>{
+					this.$set(this.list[i],'play',false);
+				})
+			},
 			confirm() {
 				if(!this.voice) return this.$showToast('请选择音色');
 				this.getOpenerEventChannel().emit('selectVoice',this.voice)
 				uni.navigateBack();
 			}
+		},
+		beforeDestroy() {
+			if (this.audioCtx) {
+				this.audioCtx.destroy();
+				this.audioCtx = null;
+			}
 		}
 	}
 </script>
@@ -57,34 +116,76 @@
 		background: #FFFFFF;
 		box-sizing: border-box;
 		
+		.top{
+			margin-top: 18rpx;
+			border-radius: 16rpx;
+			border: 1rpx solid #EEEEEE;
+			padding: 16rpx 24rpx;
+			.tl{
+				image{
+					width: 40rpx;
+					height: 22rpx;
+				}
+				text{
+					font-family: PingFangSC, PingFang SC;
+					font-weight: 400;
+					font-size: 28rpx;
+					color: #111111;
+					line-height: 40rpx;
+					margin-left: 9rpx;
+				}
+			}
+			.tr{
+				.tr_btn{
+					width: 104rpx;
+					height: 56rpx;
+					border-radius: 14rpx;
+					font-family: PingFangSC, PingFang SC;
+					font-weight: 400;
+					font-size: 28rpx;
+					color: #111111;
+					line-height: 56rpx;
+					text-align: center;
+					margin-left: 20rpx;
+					&.qx{
+						border: 1rpx solid #D1D5DB;
+					}
+					&.qr{
+						border: 1rpx solid #D9F159;
+						background: #D9F159;
+					}
+				}
+			}
+		}
+		
 		.list{
 			margin-top: 35rpx;
 			.item{
 				box-shadow: inset 0rpx -1rpx 0rpx 0rpx #E2E2E2;
-				padding: 41rpx 30rpx 41rpx 0;
+				padding: 24rpx 10rpx 24rpx 0;
 				width: 100%;
 				box-sizing: border-box;
-				&>div{
-					font-family: PingFang-SC, PingFang-SC;
-					font-weight: bold;
-					font-size: 30rpx;
-					color: #111111;
-					line-height: 32rpx;
+				.il{
+					image{
+						width: 88rpx;
+						height: 88rpx;
+					}
+					text{
+						font-family: PingFang-SC, PingFang-SC;
+						font-weight: bold;
+						font-size: 32rpx;
+						color: #111111;
+						line-height: 32rpx;
+						margin-left: 30rpx;
+					}
 				}
-				&.active{
-					&>div{
-						color: #72832B;
+				.ir{
+					image{
+						width: 40rpx;
+						height: 40rpx;
 					}
 				}
 			}
 		}
-		
-		.zt_btn{
-			width: calc(100% - 60rpx);
-			position: fixed;
-			left: 30rpx;
-			bottom: 30rpx;
-			z-index: 999;
-		}
 	}
 </style>