123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490 |
- <template>
- <view>
- <view class="bgbox" v-if="voiceflag" @click="getClose"></view>
- <view class="voice" v-if="voiceflag">
- <image :src="closeimg" class="choseimg" @click="getClose"></image>
- <view v-if="isShow">
- <view v-if="sendLock" class="tip">
- <view class="txt">试试这样说</view>
- <view class="txt-bt">科技</view>
- </view>
- <view v-else>
-
- <view class="res-txt" >
- <text :style="{
- color: (resultText == '正在识别中2...' || resultText == '未检测到语音,请重试') ?
- '#919098' :
- '#2979ff'}">
- {{resultText}}
- </text>
-
- </view>
- </view>
- </view>
-
- <view v-else class="tip">
- <view v-if="!sendLock" class="tipbox">{{voicetext}}</view>
- <view v-html="text" class="txt" style="color: #8e8d9a;"></view>
- <view v-if="!sendLock" class="prompt-loader">
-
- <view class="em" :style="randomRgb()" v-for="(item,index) in 30" :key="index"></view>
-
-
- <view class="em" :style="'background-color:' +colors[index]+';'" v-for="(item,index) in 30" :key="index"></view>
-
- </view>
- <view v-else class="prompt-loader"></view>
- </view>
-
- <view class="btn" @longpress="handleRecordStart" @touchmove="handleTouchMove" @touchend="handleRecordStop">
- <view class="btn-cont">
- 长按开始语音搜索
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- const recorderManager = uni.getRecorderManager();
-
- const innerAudioContext = uni.createInnerAudioContext();
- innerAudioContext.autoplay = true;
- export default{
- props:{
- voiceflag:{
- type: Boolean,
- default () {
- return false
- }
- }
- },
- watch:{
- sendLock(newVal, oldVal) {
- var that=this;
- recorderManager.onStop(res => {
- if (newVal) return
-
- setTimeout(function(res){
- if(!that.voicetext&&!that.partialResult){
- that.resultText='未检测到语音,请重试';
- that.sendLock=true;
- }else{
- that.resultText=that.voicetext||that.partialResult;
-
-
- setTimeout(function(){
- that.$emit('getVoice',that.resultText)
-
- that.sendLock=true;
- },1200)
- }
-
- },1000)
-
- });
- },
- },
- data(){
- return {
-
- xmmc:'',
-
- closeimg:require("@/static/images/close.png"),
-
- voiceToken: '',
- timer: null,
- text: '',
- resultText: '正在识别中...',
- startPoint: {},
- sendLock: true,
- isShow: true,
- adioFileData: '',
- adioSize: '',
- resContent: '',
- luyinStatus: true,
- voicetext:'',
- options: {},
- partialResult:'',
- colors: [],
- }
- },
- onLoad: function() {
- const colors = [];
- for (let i = 0; i < 30; i++) {
- colors.push(this.randomRgb());
- }
- this.setData({
- colors: colors
- });
- },
- mounted() {
-
-
-
- var that=this;
-
-
- plus.speech.addEventListener('start', this.ontStart, false);
- plus.speech.addEventListener('volumeChange', this.onVolumeChange, false);
- plus.speech.addEventListener('recognizing', this.onRecognizing, false);
- plus.speech.addEventListener('recognition', this.onRecognition, false);
- plus.speech.addEventListener('end', this.onEnd, false);
-
-
- recorderManager.onStop(function(res) {
-
-
-
- that.voicePath = res.tempFilePath;
-
- });
- },
- onUnload() {
- },
- unmounted() {
- },
- methods:{
- getClose(){
-
- this.sendLock=true;
- this.$emit('getClose')
- },
- onRecognizing(e){
- this.partialResult=this.partialResult+e.partialResult;
- },
-
- handleVoice() {
-
- let _this = this;
- this.options.engine = 'baidu'
-
- this.options.continue = true;
- this.options.punctuation = false;
- this.options.userInterface = false;
- plus.speech.startRecognize(this.options, (s) => {
- console.log(s,1)
- _this.voicetext+=s;
-
- });
- },
-
- handleRecordStart(e) {
- this.voicetext='';
- this.partialResult='';
- this.startPoint = e.touches[0];
- recorderManager.start({duration: 60000});
- this.handleVoice()
- this.text = `<text style="color:#333">上划取消识别</text>`;
- this.sendLock = false;
- this.isShow = false;
- this.resultText = '正在识别中...';
-
- },
-
- handleRecordStop(e) {
- var that=this;
- this.isShow = true;
- setTimeout(function(){
- plus.speech.stopRecognize();
- recorderManager.stop();
- },1200)
-
- },
-
- handleTouchMove(e) {
- let moveLenght = e.touches[e.touches.length - 1].clientY - this.startPoint.clientY;
- if (Math.abs(moveLenght) > 50) {
- this.text = `松开手指,<text style="color:#333">取消搜索</text>`;
- this.sendLock = true;
- this.isShow = false;
- } else {
- this.text = `<text style="color:#333">上划取消搜索</text>`;
- this.sendLock = false;
- this.isShow = false;
- }
- },
-
- resultClick() {
- if (this.resultText == '正在识别中...' || this.resultText == '未检测到语音,请重试') return;
- this.$emit('getVoice',this.resultText)
-
- this.sendLock=true;
-
- },
-
-
-
-
-
-
-
- randomRgb() {
- let R = Math.floor(Math.random() * 130 + 110);
- let G = Math.floor(Math.random() * 130 + 110);
- let B = Math.floor(Math.random() * 130 + 110);
- return `rgb(${R},${G},${B}, 1)`
-
- },
-
- getSeep(){
- this.voicetext='';
- this.partialResult='';
- this.voiceflag=true;
- },
- onEnd() {
-
-
-
-
-
-
-
-
-
- },
- }
- }
- </script>
- <style lang="scss" scoped>
- // 搜索
- .listtopa{border: 6rpx solid #FD5001;border-radius: 32rpx;height:64rpx;box-sizing: border-box;padding:0 140rpx 0 32rpx ;position: relative;
- input{}
- image{width: 20rpx;height: 30rpx;margin-right: 16rpx;}
- .btn{background: #FA5F03;border-radius: 32rpx;width: 120rpx;position: absolute;right: -2rpx;top: -2rpx;bottom:-2rpx;}
- }
-
- .bgbox{z-index: 1900;}
- .choseimg{width: 34rpx;height: 34rpx;position: absolute;left: 36rpx;top: 54rpx;}
- .voice {
- min-height: 500rpx;
- padding: 100rpx 60rpx 0 60rpx;
- position: relative;
- background-color: #fff;
- position: fixed;
- left:0;right:0;bottom:0;z-index: 2000;
- padding-bottom: 180rpx;
- .res-txt {
- text-align: center;
- margin-top: 40rpx;
- font-size: 36rpx;
- color: #919098;
-
- image {
- display: block;
- margin: auto;
- margin-top: 10rpx;
- width: 60rpx;
- animation: bounce-down 2.6s linear infinite;
- }
- }
-
- .tip {
- margin-top: 15rpx;
- text-align: center;
-
- .txt {
- font-size: 36rpx;
- color: #151823;
- }
-
- .txt-bt {
- margin-top: 20rpx;
- color: #919098;
- }
- }
-
- .btn {
- width: 50%;
- height: 80rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- color: #fff;
- border-radius: 50rpx;
- background: #3484fd;
- position: absolute;
- bottom: 80rpx;
- left: 50%;
- transform: translateX(-50%);
-
- .btn-cont {
- display: flex;
- align-items: center;
- }
- }
- }
-
- @-webkit-keyframes bounce-down {
- 25% {
- -webkit-transform: translateY(-10px);
- }
-
- 50%,
- 100% {
- -webkit-transform: translateY(0);
- }
-
- 75% {
- -webkit-transform: translateY(13px);
- }
- }
- .content{background-color: #f5f5f5;position: fixed;left: 0;right: 0;bottom: 0;z-index: 10000;height: 500rpx;}
- /* 语音动画 */
- .prompt-loader {
- width: 100%;
- height: 35px;
- display: flex;
- align-items: center;
- justify-content: space-between;
- margin: 30rpx auto;
- }
-
- .prompt-loader .em {
- height: 15%;
- width: 2px;
- float: left;
- display: block;
- background: #333333;
- }
-
- .prompt-loader .em:last-child {
- margin-right: 0px;
- }
-
- .prompt-loader .em:nth-child(1) {
- animation: load 1.3s 0.4s infinite linear;
- }
-
- .prompt-loader .em:nth-child(2) {
- animation: load 1.3s 0.2s infinite linear;
- }
-
- .prompt-loader .em:nth-child(3) {
- animation: load 1.3s 0.6s infinite linear;
- }
-
- .prompt-loader .em:nth-child(4) {
- animation: load 1.3s 0.8s infinite linear;
- }
-
- .prompt-loader .em:nth-child(5) {
- animation: load 1.3s 0.6s infinite linear;
- }
-
- .prompt-loader .em:nth-child(6) {
- animation: load 1.3s 0.4s infinite linear;
- }
-
- .prompt-loader .em:nth-child(7) {
- animation: load 1.3s 0.2s infinite linear;
- }
-
- .prompt-loader .em:nth-child(8) {
- animation: load 1.3s 0.6s infinite linear;
- }
-
- .prompt-loader .em:nth-child(9) {
- animation: load 1.3s 0.2s infinite linear;
- }
-
- .prompt-loader .em:nth-child(10) {
- animation: load 1.3s 0.4s infinite linear;
- }
-
- .prompt-loader .em:nth-child(11) {
- animation: load 1.3s 0.6s infinite linear;
- }
-
- .prompt-loader .em:nth-child(12) {
- animation: load 1.3s 0.8s infinite linear;
- }
-
- .prompt-loader .em:nth-child(13) {
- animation: load 1.3s 1s infinite linear;
- }
-
- .prompt-loader .em:nth-child(14) {
- animation: load 1.3s 0.2s infinite linear;
- }
-
- .prompt-loader .em:nth-child(15) {
- animation: load 1.3s 0.6s infinite linear;
- }
-
- .prompt-loader .em:nth-child(16) {
- animation: load 1.3s 0.6s infinite linear;
- }
-
- .prompt-loader .em:nth-child(17) {
- animation: load 1.3s 0.8s infinite linear;
- }
-
- .prompt-loader .em:nth-child(18) {
- animation: load 1.3s 0.2s infinite linear;
- }
-
- .prompt-loader .em:nth-child(19) {
- animation: load 1.3s 0.4s infinite linear;
- }
-
- .prompt-loader .em:nth-child(20) {
- animation: load 1.3s 0.6s infinite linear;
- }
-
- .prompt-loader .em:nth-child(21) {
- animation: load 1.3s 0.5s infinite linear;
- }
-
- .prompt-loader .em:nth-child(22) {
- animation: load 1.3s 0.2s infinite linear;
- }
-
- .prompt-loader .em:nth-child(23) {
- animation: load 1.3s 0.4s infinite linear;
- }
-
- .prompt-loader .em:nth-child(24) {
- animation: load 1.3s 0.6s infinite linear;
- }
-
- .prompt-loader .em:nth-child(25) {
- animation: load 1.3s 0.8s infinite linear;
- }
-
- .prompt-loader .em:nth-child(26) {
- animation: load 1.3s 0.2s infinite linear;
- }
-
- .prompt-loader .em:nth-child(27) {
- animation: load 1.3s 0.4s infinite linear;
- }
-
- .prompt-loader .em:nth-child(28) {
- animation: load 1.3s 0.1s infinite linear;
- }
-
- .prompt-loader .em:nth-child(29) {
- animation: load 1.3s 0.3s infinite linear;
- }
-
- .prompt-loader .em:nth-child(30) {
- animation: load 1.3s 0.6s infinite linear;
- }
-
- @keyframes load {
- 0% {
- height: 15%;
- }
-
- 50% {
- height: 100%;
- }
-
- 100% {
- height: 15%;
- }
- }
- </style>
|