iPhones在Safari通过扬声器播放音频时遇到了问题。当麦克风初始化后,我们播放一个简短的音频剪辑(大约3秒),然后用麦克风-this模式记录用户的响应三次。这第一个音频剪辑是通过手机扬声器-making音量低。然后,在麦克风记录第一用户响应之后,通过扬声器(对于所有三个音频剪辑都需要该扬声器)播放以下音频剪辑。在音频上下文目的地方面,什么会使iOS/Safari混淆?是否有一个设置,我可以设置,以确保扬声器,或另一个事件模式,我可以使用,以实现我想要的行为。想要的行为: iPhone将通过扬声器手机播放所有音频片段,即使麦克风已经初始化。
1:在“功能集”(音频回放和录音响应)之前播放一个简短的音频剪辑2:在麦克风初始化后设置超时,并启动麦克风流。他说:我们已经按照开始录制/播放音频的顺序四处游玩了。4:如果没有初始化麦克风,并且从未开始记录所需的行为。
audio = new Audio();
this.audio.src = audioUrl;
const audioFileLoadedPromise = this.audio.play()
//////////////////////////////////////////////////
const mediaStreamConstraints: MediaStreamConstraints = {
audio: !enableAudio ? false : {
echoCancellation: true,
volume: 1.0
},
video: false : (enableVideo === true ?
this.getCameraConstraints() : enableVideo),
};
navigator.mediaDevices.getUserMedia(mediaStreamConstraints)
/////////////////////////////////////////////////
await this.microphoneComponent.initComponent();
await this.microphoneComponent.startRecording();
await sleep(1000); //this pause was to test if timing somehow affected playback
this.beginAudio(); //this is the audio clip that is played through handset
////from here the pattern continues switching off between playing audio and recording user response and audio is played through speakerphone (as desired)想要的行为: iPhone将通过扬声器手机播放所有音频片段,即使麦克风已经初始化。
发布于 2021-12-15 10:14:05
对于iOS来说,这是一个已知的问题,请在这里记录bug.cgi?id=230902
我尝试过的一个解决办法是这样的(TypeScript)
public connectToSpeaker(remoteAudioStream: MediaStream, gain: number) {
try {
const AudioCtx = window.AudioContext || window['webkitAudioContext'];
const context = new AudioCtx();
const audioNode = context.createMediaStreamSource(remoteAudioStream);
const gainNode: GainNode = context.createGain();
// some device volume too low ex. iPad
gainNode.gain.value = gain;
audioNode.connect(gainNode);
gainNode.connect(context.destination);
} catch (ex) {
// will throw an exception if no audio track exists
console.error(ex)
}
}https://stackoverflow.com/questions/56191701
复制相似问题