admin管理员组文章数量:1336631
async function startListening() {
stream = await navigator.mediaDevices.getUserMedia({
audio: {
channelCount: 1,
echoCancellation: true,
autoGainControl: true,
noiseSuppression: true,
},
});
mediaRecorder = new MediaRecorder(stream);
micStream = audioMotion.audioCtx.createMediaStreamSource(stream);
audioMotion.connectInput(micStream);
mediaRecorder.ondataavailable = async (event) => {
const base64Data = await blobToBase64(event.data);
socket.send(JSON.stringify({ type: 'audioIn', data: base64Data }));
// console.log('Send voice data:', base64Data);
};
async function blobToBase64(blob) {
const reader = new FileReader();
reader.readAsDataURL(blob);
return new Promise((resolve) => {
reader.onloadend = () => resolve(reader.result.split(',')[1]);
});
}
mediaRecorder.start(1000);
}
If I am using the echoCancellation: true
it is working fine on PC but when using it on mobile devices the when volume buttons are clicked the call volume is displayed and the volume cannot be controlled unless we manually adjust the media volume. If I turn it off, the playback from the device is taken as input.
here is my Audio Playback method.
async function playAudioResponse(audioBase64) {
try {
if (!audioBase64 || audioBase64.trim() === '') {
// console.error('Empty or invalid audio data received.');
return;
}
const binaryString = atob(audioBase64);
const len = binaryString.length;
const buffer = new Float32Array(len); // 8-bit
for (let i = 0; i < len; i++) {
buffer[i] = decodeSample(binaryString.charCodeAt(i)) / 32768;
}
// console.log('buffer', buffer)
audioWriter(buffer).then((data) => {
audioMotion.connectInput(micStream);
audioMotion.volume = 1;
}).catch((error) => {
// console.error('Error writing audio data:', error);
});
} catch (error) {
console.error('Error playing audio:', error);
}
}
And in the above play audio response, i am using a WebAudioWrite
which uses AudioWorkletNode
Thanks in advance.
本文标签: Issue with Javascript Audio OutputOn Android Mobile Devices Considered as Call VolumeStack Overflow
版权声明:本文标题:Issue with Javascript Audio Output | On Android Mobile Devices Considered as Call Volume - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742408012a2469218.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论