关于小程序uniapp同声传译(语音转文字)

1. 首先我们先在开发者工具给他添加第三方插件

然后我们在 小程序的manifest.json切换成源码视图 然后在appid同级目录添加插件 其中provider是第三方插件的appid

然后在你要进行翻译的文件里面引入

 

<template>
	<view>
		<view class="voicepad">
			{{voiceState}}
		</view>
		<button class="cu-btn  bg-green voicebtn " @touchstart="touchStart" @touchend="touchEnd">
			<image src="../../static/yuyue/maikef.png" mode="widthFix" style="width: 50rpx;"></image>
		</button>
		<view class="center" style="background-color: #555555; color: #FFF;" v-show="isShow">
			正在录音...
		</view>
	</view>
</template>

<script>
	var plugin = requirePlugin("WechatSI")
	let manager = plugin.getRecordRecognitionManager();

	export default {
		data() {
			return {
				voiceState: "你可以这样说...",
				isShow: false
			}
		},
		onShow() {

		},
		onLoad() {
			this.initRecord();
		},
		methods: {
			touchStart: function() {
				// uni.showToast({
				// 		title: '正在录音',
				// 		icon: "none"
				// 	})
				this.isShow = true
				manager.start({
					duration: 60000,
					lang: "zh_CN"
				});
			},
			touchEnd: function() {
				// uni.showToast({
				// 		title: '录音完成',
				// 		icon: "none"
				// 	})
				this.isShow = false
				manager.stop();
			},
			/**  
			 * 初始化语音识别回调  
			 * 绑定语音播放开始事件  
			 */
			initRecord: function() {
				manager.onStart = function(res) {
					console.log('start',res.msg);
				this.voiceState = res.msg;
				};
				//有新的识别内容返回,则会调用此事件  
				manager.onRecognize = (res) => {
					this.voiceState = res.result;
					console.log('onRecognize');
				}

				// 识别结束事件  
				manager.onStop = (res) => {
					this.voiceState = res.result;
					console.log('onStop',res.result);
				}

				// 识别错误事件  
				manager.onError = (res) => {
					this.voiceState = res.msg;
					console.log('onError');

				}
			},
		}
	}
</script>

<style>
	.voicebtn {
		height: 130upx;
		display: block;
		width: 130upx;
		line-height: 130upx;
		border-radius: 65upx;
		font-size: 50upx;
		position: absolute;
		top: 1060upx;
		left: 310upx;
	}

	.voicepad {
		height: 250upx;
		width: 680upx;
		background: #fff;
		margin: 30upx auto;
		border-radius: 8upx;

		padding: 20upx;
		font-size: 35upx;
	}

	.center {
		text-align: center;
		align-items: center;
		width: 200rpx;
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		padding: 20rpx;
		border-radius: 20rpx;
		/* 	height: 50rpx; */
		opacity: 0.8;
	}
</style>

 

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值