uniapp 如何调用音频

uniapp调用音频

button点击

powershell 复制代码
       <view>
       <button @click="startPlay">开始播放</button>
       </view>

方法实现

powershell 复制代码
  startPlay() {  
      const innerAudioContext = uni.createInnerAudioContext();
      innerAudioContext.src = '/static/sounds/oqc.mp3';
      innerAudioContext.play()
       }

自定义播放 本地调试可以 打包 APK调用失败(需补充使用)

powershell 复制代码
  startPlay() {  
     this.a(); // 开始播放的入口 
     },  
     a(){

         var time = new Date();
          console.log('time:',time)
          const asd = '请001号前来办理业务'
          const msg = new SpeechSynthesisUtterance()
          msg.text = asd
          let that = this
          msg.onend = function(){
            that.count+=1
            // alert('播放结束')
            setTimeout(function(){
          that.play()

            },1000)
          }
          window.speechSynthesis.speak(msg)
    },
     play(){
          console.log('this.count',this.count)
          if(this.count < 3){
            this.a()
          }else{
            this.count = 0
            console.log('播放完毕')
          }
          // setInterval(this.cyclePlay(),1000)
        },
相关推荐
云天AI实战派18 分钟前
ChatGPT/API 调用故障排查指南:Realtime 音频、智能体浏览器操作与 AI 编码代理全流程修复手册
人工智能·chatgpt·音视频
阳火锅19 分钟前
💡 告别类名地狱!Tailwind CSS 语义化转换神器来了
前端·css·vue.js
ricardo197322 分钟前
Core Web Vitals 全解:LCP / INP / CLS 逐个击破
前端
VillenK24 分钟前
版本依赖问题:vite-plugin-dts@3.1.0 与 jiti 的兼容性
前端·typescript·vite
Apifox44 分钟前
如何在 Apifox 中快速构建和调试 AI Agent
前端·agent·ai编程
一晌贪欢i1 小时前
WebContainer 重点介绍
前端·webcontainer
山河木马1 小时前
Emscripten 从 C/C++ 调用 JavaScript
前端·javascript·c++
鹏程十八少1 小时前
12. Android 协程通关秘籍:31 道资深工程师面试题精讲
前端·后端·面试
Dlrb12111 小时前
C语言-字符串指针与函数指针
java·c语言·前端
PBitW1 小时前
组件封装注意事项
前端·vue.js