简体   繁体   English

Safari iOS上的录音为空

[英]Audio recording is empty on safari ios

I've used RecordRTC in order to record audio and send it to a speech-to-text API. 我使用RecordRTC来记录音频并将其发送到语音文本API。

Somehow, it all works perfectly fine except for using Safari IOS. 不知何故,除了使用Safari IOS之外,其他所有功能都可以正常工作。
While using Safari IOS, the recording which I'm retrieving as base64 string, 在使用Safari IOS时,我以base64字符串形式检索的记录,
is somehow returned empty from the recorder object. 从记录器对象以某种方式返回为空。

Previous questions asked about it were answered to use another library, 先前询问过的问题已回答使用另一个库,
yet the docs for RecordRTC specifically says it fully supports Safari IOS. 但是RecordRTC的文档专门说它完全支持Safari IOS。

Could you please help me figuring out the problem and finding a workaround? 您能帮我解决问题并找到解决方法吗?
My code: 我的代码:

    async initMic() {
      let stream = await navigator.mediaDevices.getUserMedia({video: false, audio: true});
      mic = new RecordRTCPromisesHandler(stream, { 
        type: 'audio',
        mimeType: 'audio/wav',
        recorderType: RecordRTC.StereoAudioRecorder,
        sampleRate: 48000,
        numberOfAudioChannels: 1,
      });
    },

    async sendRecording() {
      let vm = this;
      mic.stopRecording(function() {
        mic.getDataURL(function(dataURL) {
            vm.$store.dispatch('UpdateAudioBase64', dataURL.replace('data:audio/wav;base64,', ''));
            mic.reset();
            vm.$emit('send-recording');
        });
      });
    },

** The string 'replace' function is meant to remove the base64 header **字符串“替换”功能用于删除base64标头
before sending it to speech-to-text API (API's needs). 在将其发送到语音转文本API之前(API的需求)。

Thank You! 谢谢!

If not mistaken, apple fu... messed up again with their dumb policy, problem is you can't do a lot of things(like setting up recorder) without USER trigger them, 如果没记错的话,Apple fu ...他们的愚蠢政策又搞砸了,问题是如果没有USER触发,您将无法做很多事情(例如设置录音机),

so you should wrap your recorder in click event listener, user click button, then your mic = new RecordRTCPromisesHandler(stream, {... etc fires and recording starts. 因此,您应该将记录器包装在单击事件监听器中,然后单击用户单击按钮,然后mic = new RecordRTCPromisesHandler(stream, {... etc会触发并开始记录。

check this example https://github.com/muaz-khan/RecordRTC/blob/master/simple-demos/audio-recording.html 检查这个例子https://github.com/muaz-khan/RecordRTC/blob/master/simple-demos/audio-recording.html

here this trick works 这把戏在这里

btw your code works in mac safari? 顺便说一句,您的代码可以在Mac Safari中使用吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM