Skip to content

Commit

Permalink
fixed few issues regarding speech to text
Browse files Browse the repository at this point in the history
  • Loading branch information
jibon57 committed Nov 2, 2023
1 parent c313ccf commit a01bac0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 23 deletions.
1 change: 1 addition & 0 deletions src/assets/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@
"subtitle-font-size": "Subtitle font size",
"enable-translation": "Enable translation",
"translation-langs-label": "Translation languages",
"default-subtitle-lang-label": "Default subtitle language",
"enable-service": "Enable service",
"speech-user-required": "At least one speech user require",
"speech-lang-required": "At least one speech language require",
Expand Down
11 changes: 10 additions & 1 deletion src/components/speech-to-text-service/history/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@ import { Popover } from '@headlessui/react';
import { useTranslation } from 'react-i18next';

import PopoverPanelElms from './popoverPanelElms';
import { store } from '../../../store';

interface SubtitleTextsHistoryProps {
isOpenPopover: (open: boolean) => void;
}

const SubtitleTextsHistory = ({ isOpenPopover }: SubtitleTextsHistoryProps) => {
const { t } = useTranslation();
const [showPopover, setShowPopover] = useState<boolean>(true);
const [showPopover, setShowPopover] = useState<boolean>(false);

useEffect(() => {
const isRecorder = store.getState().session.currentUser?.isRecorder;
if (!isRecorder) {
setShowPopover(true);
}
//eslint-disable-next-line
}, []);

useEffect(() => {
isOpenPopover(showPopover);
Expand Down
45 changes: 23 additions & 22 deletions src/components/speech-to-text-service/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const SpeechToTextService = ({ currentRoom }: SpeechToTextServiceProps) => {
>(undefined);
const [optionSelectionDisabled, setOptionSelectionDisabled] =
useState<boolean>(false);
const [isOpenPopover, setIsOpenPopover] = useState<boolean>(true);
const [isOpenPopover, setIsOpenPopover] = useState<boolean>(false);

// by default, we'll select the first language as default subtitle
useEffect(() => {
Expand All @@ -79,11 +79,8 @@ const SpeechToTextService = ({ currentRoom }: SpeechToTextServiceProps) => {
//eslint-disable-next-line
}, []);

// if we've an active mic for room + speech to text on
// sometime it make confused to user if they would like to mute/unmute
// so, we'll do the same if a user tries to mute/unmute their room mic
useEffect(() => {
const handleUserMutedMic = (publication: TrackPublication) => {
const handleUserMutedMic = useCallback(
(publication: TrackPublication) => {
if (!createdMediaStream) {
return;
}
Expand All @@ -92,8 +89,14 @@ const SpeechToTextService = ({ currentRoom }: SpeechToTextServiceProps) => {
t.enabled = !publication.isMuted;
});
}
};
},
[createdMediaStream],
);

// if we've an active mic for room + speech to text on
// sometime it make confused to user if they would like to mute/unmute
// so, we'll do the same if a user tries to mute/unmute their room mic
useEffect(() => {
currentRoom.localParticipant.on(
ParticipantEvent.TrackMuted,
handleUserMutedMic,
Expand All @@ -102,21 +105,6 @@ const SpeechToTextService = ({ currentRoom }: SpeechToTextServiceProps) => {
ParticipantEvent.TrackUnmuted,
handleUserMutedMic,
);

if (createdMediaStream) {
// in the beginning we'll check mic status
if (currentRoom.localParticipant.audioTracks.size) {
currentRoom.localParticipant.audioTracks.forEach((t) => {
if (t.isMuted) {
createdMediaStream.getAudioTracks().forEach((t) => {
if (t.enabled) {
t.enabled = false;
}
});
}
});
}
}
return () => {
currentRoom.localParticipant.off(
ParticipantEvent.TrackMuted,
Expand Down Expand Up @@ -196,6 +184,19 @@ const SpeechToTextService = ({ currentRoom }: SpeechToTextServiceProps) => {
}
setCreatedMediaStream(mStream);

// for the beginning, we'll check if our room mic is muted or not
if (currentRoom.localParticipant.audioTracks.size) {
currentRoom.localParticipant.audioTracks.forEach((t) => {
if (t.isMuted && mStream) {
mStream.getAudioTracks().forEach((t) => {
if (t.enabled) {
t.enabled = false;
}
});
}
});
}

openConnectionWithAzure(
azureTokenInfo,
mStream,
Expand Down
4 changes: 4 additions & 0 deletions src/components/speech-to-text-service/selectOptions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ const SelectOptions = ({
store.getState().speechServices.selectedSubtitleLang;
if (!isEmpty(selectedSubtitleLang)) {
setSelectedSubtitleLang(selectedSubtitleLang);
} else {
if (speechService.default_subtitle_lang) {
setSelectedSubtitleLang(speechService.default_subtitle_lang);
}
}
//eslint-disable-next-line
}, []);
Expand Down

0 comments on commit a01bac0

Please sign in to comment.