Selaa lähdekoodia

抖音不要语音播放

黎海 2 vuotta sitten
vanhempi
commit
77160d472c
2 muutettua tiedostoa jossa 47 lisäystä ja 159 poistoa
  1. 46 139
      src/pages/chat/index.jsx
  2. 1 20
      src/pages/chat/index.less

+ 46 - 139
src/pages/chat/index.jsx

@@ -6,8 +6,6 @@ import './index.less'
6 6
 import tool from '../../common/tool'
7 7
 
8 8
 export default class Albums_play extends Component {
9
-  plugin = requirePlugin("WechatSI");
10
-  manager = this.plugin.getRecordRecognitionManager();
11 9
   options = {
12 10
     sampleRate: 44100,
13 11
     numberOfChannels: 1,
@@ -35,9 +33,8 @@ export default class Albums_play extends Component {
35 33
   }
36 34
 
37 35
   componentDidShow () {
38
-    console.log('页面启动',this.state.userId);
36
+    console.log('页面启动', this.state.userId);
39 37
     this.userinfo()
40
-    this.initRecord()
41 38
     // this.setState({
42 39
     //   userId: this.generateUserID()
43 40
     // })
@@ -65,29 +62,29 @@ export default class Albums_play extends Component {
65 62
   // })
66 63
 
67 64
   componentDidHide () { }
68
-  
65
+
69 66
   // 获取用户信息并且登录,获取openid
70 67
   userinfo () {
71 68
     var that = this;
72 69
     that.setState({
73 70
       login: false
74 71
     })
75
-    Taro.getUserInfo({
76
-      success: function (res) {
77
-        console.log(res, 'userinfo');
78
-        var userInfo = res.userInfo
79
-        var nickName = userInfo.nickName
80
-        var avatarUrl = userInfo.avatarUrl
81
-        var gender = userInfo.gender //性别 0:未知、1:男、2:女
82
-        var province = userInfo.province
83
-        var city = userInfo.city
84
-        var country = userInfo.country
85
-        let data = {
86
-          "user_name": nickName,
87
-          "user_img": avatarUrl
88
-        };
89
-      }
90
-    })
72
+    // Taro.getUserInfo({
73
+    //   success: function (res) {
74
+    //     console.log(res, 'userinfo');
75
+    //     var userInfo = res.userInfo
76
+    //     var nickName = userInfo.nickName
77
+    //     var avatarUrl = userInfo.avatarUrl
78
+    //     var gender = userInfo.gender //性别 0:未知、1:男、2:女
79
+    //     var province = userInfo.province
80
+    //     var city = userInfo.city
81
+    //     var country = userInfo.country
82
+    //     let data = {
83
+    //       "user_name": nickName,
84
+    //       "user_img": avatarUrl
85
+    //     };
86
+    //   }
87
+    // })
91 88
   }
92 89
   // 提交文字
93 90
   submitTo () {
@@ -138,19 +135,19 @@ export default class Albums_play extends Component {
138 135
         })
139 136
       }
140 137
     })
141
-    .catch(res=>{
142
-      console.log("请求超时");
143
-      this.setState({
144
-        sendDisabled: true,//是否禁用发送按钮
145
-        value: '',
146
-        height: 63,
147
-        userId: 0,
148
-        isAnswer: true,//机器人是否已经回答
149
-        isRecognize: false,
150
-        showResult: false,
151
-        isSpeechSounds: false,//是否是语音写入
138
+      .catch(res => {
139
+        console.log("请求超时");
140
+        this.setState({
141
+          sendDisabled: true,//是否禁用发送按钮
142
+          value: '',
143
+          height: 63,
144
+          userId: 0,
145
+          isAnswer: true,//机器人是否已经回答
146
+          isRecognize: false,
147
+          showResult: false,
148
+          isSpeechSounds: false,//是否是语音写入
149
+        })
152 150
       })
153
-    })
154 151
   }
155 152
   //文字输入
156 153
   focus (e) {
@@ -178,76 +175,6 @@ export default class Albums_play extends Component {
178 175
       isSpeechSounds: !this.state.isSpeechSounds
179 176
     })
180 177
   }
181
-  // 初始化语音识别
182
-  initRecord () {
183
-    let that = this
184
-    console.log('initRecord');
185
-    this.manager.onRecognize = (res) => {
186
-      console.log("current result", res.result);
187
-    };
188
-    // 识别错误事件
189
-    this.manager.onError = function (res) {
190
-      Taro.hideLoading();
191
-    }
192
-    this.manager.onStop = (res) => {
193
-      Taro.hideLoading();
194
-      // 去除语音识别出的特殊符号
195
-      const text = res.result.replace(
196
-        /[`~%!@#^=''?~《》!@#¥……&——‘”“'?*()(),,。.、<>]/g,
197
-        ""
198
-      );
199
-      console.log(text, 'text');
200
-      if (text) {
201
-        that.sendText(text)
202
-        that.setState({
203
-          value: text
204
-        })
205
-        // 识别结果展示1.5秒后收起                               
206
-        setTimeout(() => {
207
-          that.setState({
208
-            isRecognize: false,
209
-            showResult: false,
210
-          })
211
-
212
-        }, 1500);
213
-      } else {
214
-
215
-        setTimeout(() => {
216
-          that.setState({
217
-            isRecognize: false,
218
-            showResult: false,
219
-          })
220
-        }, 1500);
221
-      }
222
-      that.setState({
223
-        showResult: true
224
-      })
225
-    };
226
-    this.manager.onError = (res) => {
227
-      Taro.hideLoading();
228
-      if (res.msg) {
229
-        Taro.showToast({ title: res.msg, icon: "none" });
230
-      }
231
-    };
232
-  };
233
-  // 开始录音
234
-  startRecognize = () => {
235
-    wx.vibrateShort()
236
-    Taro.showLoading({ title: "录音中..." });
237
-    this.setState({
238
-      isRecognize: true,
239
-      value: '',
240
-    })
241
-    this.manager.start({ duration: 30000, lang: "zh_CN" });
242
-  };
243
-  // 结束录音
244
-  endRecognize = () => {
245
-    console.log("endRecognize");
246
-    Taro.hideLoading();
247
-    Taro.showLoading({ title: "识别中..." });
248
-    this.manager.stop();
249
-
250
-  };
251 178
 
252 179
   render () {
253 180
     return (
@@ -301,42 +228,22 @@ export default class Albums_play extends Component {
301 228
             <View className='in_voice_icon_tips'>机器人思考中...</View>
302 229
           }
303 230
           <View className="sendmessage" style={`bottom:${this.state.input_bottom}px`}>
304
-            <Image className='add_icon' style={!this.state.isAnswer ? 'opacity: .3;' : ''} onClick={e => (this.changeSpeak(e))} id='1' src='https://we-spa.oss-cn-shenzhen.aliyuncs.com/total_picture/1677739244529.png'></Image>
305
-            {
306
-              this.state.isSpeechSounds ?
307
-                <View
308
-                  className="recognize-btn view-center"
309
-                  onClick={() => {
310
-                    // 按住按钮时间过短只会触发点击事件
311
-                    Taro.hideLoading();
312
-                    Taro.showToast({ title: "请长按说话", icon: "error" });
313
-                  }}
314
-                  onLongPress={e => (this.startRecognize())}
315
-                  onTouchEnd={e => (this.endRecognize())}
316
-                >
317
-                  <View>
318
-                    {this.state.isRecognize
319
-                      ? "松开发送"
320
-                      : "按住说话"}
321
-                  </View>
322
-                </View>
323
-                :
324
-                <Input
325
-                  autoHeight
326
-                  disabled={!this.state.isAnswer}
327
-                  id='advice_textarea'
328
-                  cursorSpacing='5'
329
-                  showConfirmBar=''
330
-                  confirmType='send'
331
-                  onConfirm={e => (this.submitTo(e))}
332
-                  adjustPosition
333
-                  value={this.state.value}
334
-                  onFocus={e => (this.focus(e))}
335
-                  onBlur={e => (this.blur(e))}
336
-                  onKeyboardHeightChange={e => (this.onKeyboardHeightChange(e))}
337
-                  onLineChange={e => (this.onLineChange(e))}
338
-                  placeholder="请输入您要咨询的问题" />
339
-            }
231
+            <Input
232
+              autoHeight
233
+              disabled={!this.state.isAnswer}
234
+              id='advice_textarea'
235
+              className='advice_textarea'
236
+              cursorSpacing='5'
237
+              showConfirmBar=''
238
+              confirmType='send'
239
+              onConfirm={e => (this.submitTo(e))}
240
+              adjustPosition
241
+              value={this.state.value}
242
+              onFocus={e => (this.focus(e))}
243
+              onBlur={e => (this.blur(e))}
244
+              onKeyboardHeightChange={e => (this.onKeyboardHeightChange(e))}
245
+              onLineChange={e => (this.onLineChange(e))}
246
+              placeholder="请输入您要咨询的问题" />
340 247
 
341 248
             <Button onClick={e => (this.submitTo(e))}
342 249
               disabled={this.state.sendDisabled}

+ 1 - 20
src/pages/chat/index.less

@@ -35,24 +35,8 @@ page {
35 35
   align-items: flex-end;
36 36
   flex-direction: row;
37 37
 }
38
-.add_icon {
39
-  width: 60px;
40
-  height: 60px;
41
-  margin: 0 auto;
42
-}
43 38
 
44
-.sendmessage Input {
45
-  flex: 1;
46
-  padding: 10px;
47
-  height: 60px;
48
-  border-radius: 10px;
49
-  // max-height: 150px;
50
-  background-color: #f8f8f8;
51
-  font-size: 32px;
52
-  margin-left: 20px;
53
-  padding-left: 20px;
54
-}
55
-.recognize-btn{
39
+.sendmessage .advice_textarea {
56 40
   flex: 1;
57 41
   padding: 10px;
58 42
   height: 60px;
@@ -62,9 +46,6 @@ page {
62 46
   font-size: 32px;
63 47
   margin-left: 20px;
64 48
   padding-left: 20px;
65
-  display: flex;
66
-  justify-content: center;
67
-  align-items: center;
68 49
 }
69 50
 
70 51
 .sendmessage button {