Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
GenieShen opened this issue Mar 13, 2024 · 2 comments

Comments

@GenieShen
Copy link

image
<div className={${chatStyle["chat-input-action"]} clickable} onMouseDown={(e) => startRecorder(e)} onMouseUp={(e) => endRecorder(e)} onTouchStart={(e) => startRecorder(e)} onTouchEnd={(e) => endRecorder(e)} > <MicIcon /> </div>
`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
Copy link
Owner

xiangyuecn commented Mar 13, 2024

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

@GenieShen
Copy link
Author

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants