fix(audio): forcefully disable stereo when using Vosk transcription

The current Vosk CC provider does not support stereo mic streams
(pending investigation as to why).

This commits makes sure stereo is forcefully disabled via SDP munging
only when transcription is active and using Vosk. Having it disabled
in the server side (FreeSWITCH) is not enough because the stereo parameter
is client mandated and replicated by FS on its answer. So we need to
make sure it's always disabled for the time being.
SFU audio does munging server side (and stereo is always off), so no changes
needed there.

The rest of the providers (except WebSpeech) need to be validated against
stereo audio as well.
This is also intended to be temporary - ideally this needs to be fixed in
mod_audio_fork/Vosk/wherever this is breaking.
This commit is contained in:
prlanzarin 2023-01-31 14:04:17 -03:00 committed by Lucas Fialho Zawacki
parent 4400cc68c8
commit 54b6578b03
3 changed files with 25 additions and 0 deletions

View File

@ -12,6 +12,7 @@ import {
filterValidIceCandidates,
analyzeSdp,
logSelectedCandidate,
forceDisableStereo,
} from '/imports/utils/sdpUtils';
import { Tracker } from 'meteor/tracker';
import VoiceCallStates from '/imports/api/voice-call-states';
@ -25,6 +26,7 @@ import {
filterSupportedConstraints,
doGUM,
} from '/imports/api/audio/client/bridge/service';
import SpeechService from '/imports/ui/components/audio/captions/speech/service';
const MEDIA = Meteor.settings.public.media;
const MEDIA_TAG = MEDIA.mediaTag;
@ -708,12 +710,25 @@ class SIPSession {
const target = SIP.UserAgent.makeURI(`sip:${callExtension}@${hostname}`);
const matchConstraints = getAudioConstraints({ deviceId: this.inputDeviceId });
const sessionDescriptionHandlerModifiers = [];
const iceModifiers = [
filterValidIceCandidates.bind(this, this.validIceCandidates),
];
if (!SIPJS_ALLOW_MDNS) iceModifiers.push(stripMDnsCandidates);
// The current Vosk provider does not support stereo when transcribing
// microphone streams, so we need to make sure it is forcefully disabled
// via SDP munging. Having it disabled on server side FS _does not suffice_
// because the stereo parameter is client-mandated (ie replicated in the
// answer)
if (SpeechService.stereoUnsupported()) {
logger.debug({
logCode: 'sipjs_transcription_disable_stereo',
}, 'Transcription provider does not support stereo, forcing stereo=0');
sessionDescriptionHandlerModifiers.push(forceDisableStereo);
}
const inviterOptions = {
sessionDescriptionHandlerOptions: {
constraints: {
@ -724,6 +739,7 @@ class SIPSession {
},
iceGatheringTimeout: ICE_GATHERING_TIMEOUT,
},
sessionDescriptionHandlerModifiers,
sessionDescriptionHandlerModifiersPostICEGathering: iceModifiers,
delegate: {
onSessionDescriptionHandler:

View File

@ -168,6 +168,8 @@ const getLocale = () => {
return locale;
};
const stereoUnsupported = () => isActive() && isVosk() && !!getSpeechLocale();
export default {
LANGUAGES,
hasSpeechRecognitionSupport,
@ -184,4 +186,5 @@ export default {
getStatus,
generateId,
useFixedLocale,
stereoUnsupported,
};

View File

@ -333,6 +333,11 @@ const logSelectedCandidate = async (peer, isIpv6) => {
});
};
const forceDisableStereo = ({ sdp, type }) => ({
sdp: sdp.replace(/stereo=1/ig, 'stereo=0'),
type,
});
export {
interop,
isUnifiedPlan,
@ -342,4 +347,5 @@ export {
filterValidIceCandidates,
analyzeSdp,
logSelectedCandidate,
forceDisableStereo,
};