码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 小程序 语音搜索功能,语音识别翻译成文本进行搜索


    1.使用的是wepy框架。

    <view class="{{recordState?'speakInfoActive':'speakInfo'}}" catchtouchstart="touchStart" catchtouchend="touchEnd">按住说话view>

    2.js部分

    1. const plugin = requirePlugin('WechatSI');
    2. const manager = plugin.getRecordRecognitionManager();
    3. export default class send extends wepy.page {
    4. config = {
    5. navigationBarTitleText: '搜索'
    6. };
    7. data = {
    8. recordState: false, //录音状态
    9. }
    10. onLoad(option) {
    11. this.initRecord();
    12. }
    13. }
    14. initRecord(){
    15. manager.stop()
    16. const that = this;
    17. // 有新的识别内容返回,则会调用此事件
    18. manager.onRecognize = function (res) {
    19. console.log(res)
    20. }
    21. manager.onStart = function (res) {
    22. console.log("成功开始录音识别", res)
    23. }
    24. // 识别错误
    25. manager.onError = function (res) {
    26. wx.showToast({
    27. title: `请等待识别完成!`,
    28. icon: 'none',
    29. duration: 2000
    30. })
    31. console.error("error msg", res)
    32. }
    33. //识别结束
    34. manager.onStop = function (res) {
    35. if (res.result == '') {
    36. wx.showModal({
    37. title: '提示',
    38. content: '听不清楚,请重新说一遍!',
    39. showCancel: false,
    40. success: function (res) {}
    41. })
    42. return;
    43. }
    44. that.searchValue = res.result.slice(0, -1)
    45. that.searchFun()
    46. that.$apply()
    47. }
    48. }
    49. //开始
    50. touchStart(e){
    51. const that = this;
    52. that.recordState=true
    53. that.$apply()
    54. manager.start({ lang: 'zh_CN'})
    55. }
    56. //结束
    57. touchEnd(e){
    58. const that = this;
    59. that.recordState=false
    60. that.$apply()
    61. manager.stop();
    62. }
    63. }

    3.样式

    1. .speakInfo{
    2. margin: 1rpx auto;
    3. margin-top: 20rpx;
    4. width: 140rpx;
    5. height: 60rpx;
    6. line-height: 60rpx;
    7. border: 0.5px solid #999;
    8. border-radius: 30rpx;
    9. font-size: 26rpx;
    10. color: #999999;
    11. text-align: center;
    12. }
    13. .speakInfoActive{
    14. margin: 1rpx auto;
    15. margin-top: 20rpx;
    16. width: 140rpx;
    17. height: 60rpx;
    18. line-height: 60rpx;
    19. border: 0.5px solid #3a85fa;
    20. border-radius: 30rpx;
    21. font-size: 26rpx;
    22. color:#ffffff;
    23. text-align: center;
    24. background: #3a85fa;
    25. }

  • 相关阅读:
    c语言编程Turbo C编译、毗连和运行时的常见差错
    全球国家行政区划边界(中国科学院地理科学与资源研究所)
    语法基础(变量、输入输出、表达式与顺序语句完成情况)
    Vue3【十】07使用ref创建基本类型的响应式数据以及ref和reactive区别
    FastReport Online Designer 2023
    算法----BF算法&KMP算法
    子组件向父组件传参的方式?
    [代码学习]einsum详解
    leetcode_2586 统计范围元音字符串
    Solidity智能合约开发 — 4.3-合约的事件和继承
  • 原文地址:https://blog.csdn.net/qq_44890362/article/details/133317678
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号