xiangyuecn / Recorder

html5 js 录音 mp3 wav ogg webm amr g711a g711u 格式,支持pc和Android、iOS部分浏览器、Hybrid App(提供Android iOS App源码)、微信,提供ASR语音识别转文字 H5版语音通话聊天示例 DTMF编码解码
https://xiangyuecn.github.io/Recorder/
MIT License
4.59k stars 1.01k forks source link

请问每次录音第一次都不成功,第二次才成功录上怎么解决 #214

Open GenieShen opened 3 months ago

GenieShen commented 3 months ago

image <div className={${chatStyle["chat-input-action"]} clickable`} onMouseDown={(e) => startRecorder(e)} onMouseUp={(e) => endRecorder(e)} onTouchStart={(e) => startRecorder(e)} onTouchEnd={(e) => endRecorder(e)}

const startRecorder = (e: any) => { // 调用open方法进行授权 rec.open( function () { console.log("授权成功,开始录音"); rec.start(); }, function (msg: any, isUserNotAllow: any) { //用户拒绝未授权或不支持 console.log("用户拒绝未授权或不支持", msg); }, function (msg: any) { alert(msg); }, ); // 开始录音 // rec.start(); };

const endRecorder = (e: any) => { // 停止录音 rec.stop( async function (blob: any, duration: any) { // 创建指向音频文件的URL // var audioURL = (window.URL || webkitURL).createObjectURL(blob); // 把MP3文件传输到openai const file = new File([blob], "test.mp3", { type: "audio/mpeg", }); const transcription = await openai.audio.transcriptions.create({ file: file, model: "whisper-1", }); console.log("语音转文字结果:", transcription.text); // 回显在聊天框中 props.setSpeechToText(transcription.text); }, function (msg: any) { console.log(msg); }, function () { // 释放录音资源 rec.close(); rec = null; }, ); };`

xiangyuecn commented 3 months ago

日志里面有个编号Recorder:28 | 29,开头的start 和 stop 并不是同一个rec,你同一时间调用了两次你的startRecorder之类的方法

GenieShen commented 3 months ago

日志里面有个编号Recorder:28 | 29,开头的start 和 stop 并不是同一个rec,你同一时间调用了两次你的startRecorder之类的方法

请问有啥办法能解决吗,我打印日志看是只调了一次startRecorder方法的,(能放我进群吗大佬,申请了好几次没人处理