Skip to content

Commit 5d56f48

Browse files
authored
👋 feat: remove Edge TTS (#6885)
* feat: remove Edge TTS * remove the remaining edge code * chore: cleanup * chore: cleanup package-lock
1 parent c49f883 commit 5d56f48

File tree

13 files changed

+63
-547
lines changed

13 files changed

+63
-547
lines changed

client/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
"lodash": "^4.17.21",
7474
"lucide-react": "^0.394.0",
7575
"match-sorter": "^6.3.4",
76-
"msedge-tts": "^2.0.0",
7776
"qrcode.react": "^4.2.0",
7877
"rc-input-number": "^7.4.2",
7978
"react": "^18.2.0",

client/src/common/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export enum STTEndpoints {
2929

3030
export enum TTSEndpoints {
3131
browser = 'browser',
32-
edge = 'edge',
3332
external = 'external',
3433
}
3534

client/src/components/Audio/TTS.tsx

Lines changed: 2 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
import { useEffect, useMemo } from 'react';
33
import { useRecoilValue } from 'recoil';
44
import type { TMessageAudio } from '~/common';
5-
import { useLocalize, useTTSBrowser, useTTSEdge, useTTSExternal } from '~/hooks';
6-
import { VolumeIcon, VolumeMuteIcon, Spinner } from '~/components/svg';
7-
import { useToastContext } from '~/Providers/ToastContext';
5+
import { useLocalize, useTTSBrowser, useTTSExternal } from '~/hooks';
6+
import { VolumeIcon, VolumeMuteIcon, Spinner } from '~/components';
87
import { logger } from '~/utils';
98
import store from '~/store';
109

@@ -85,97 +84,6 @@ export function BrowserTTS({ isLast, index, messageId, content, className }: TMe
8584
);
8685
}
8786

88-
export function EdgeTTS({ isLast, index, messageId, content, className }: TMessageAudio) {
89-
const localize = useLocalize();
90-
const playbackRate = useRecoilValue(store.playbackRate);
91-
const isBrowserSupported = useMemo(
92-
() => typeof MediaSource !== 'undefined' && MediaSource.isTypeSupported('audio/mpeg'),
93-
[],
94-
);
95-
96-
const { showToast } = useToastContext();
97-
const { toggleSpeech, isSpeaking, isLoading, audioRef } = useTTSEdge({
98-
isLast,
99-
index,
100-
messageId,
101-
content,
102-
});
103-
104-
const renderIcon = (size: string) => {
105-
if (isLoading === true) {
106-
return <Spinner size={size} />;
107-
}
108-
109-
if (isSpeaking === true) {
110-
return <VolumeMuteIcon size={size} />;
111-
}
112-
113-
return <VolumeIcon size={size} />;
114-
};
115-
116-
useEffect(() => {
117-
const messageAudio = document.getElementById(`audio-${messageId}`) as HTMLAudioElement | null;
118-
if (!messageAudio) {
119-
return;
120-
}
121-
if (playbackRate != null && playbackRate > 0 && messageAudio.playbackRate !== playbackRate) {
122-
messageAudio.playbackRate = playbackRate;
123-
}
124-
}, [audioRef, isSpeaking, playbackRate, messageId]);
125-
126-
logger.log(
127-
'MessageAudio: audioRef.current?.src, audioRef.current',
128-
audioRef.current?.src,
129-
audioRef.current,
130-
);
131-
132-
return (
133-
<>
134-
<button
135-
className={className}
136-
onClickCapture={() => {
137-
if (!isBrowserSupported) {
138-
showToast({
139-
message: localize('com_nav_tts_unsupported_error'),
140-
status: 'error',
141-
});
142-
return;
143-
}
144-
if (audioRef.current) {
145-
audioRef.current.muted = false;
146-
}
147-
toggleSpeech();
148-
}}
149-
type="button"
150-
title={isSpeaking === true ? localize('com_ui_stop') : localize('com_ui_read_aloud')}
151-
>
152-
{renderIcon('19')}
153-
</button>
154-
{isBrowserSupported ? (
155-
<audio
156-
ref={audioRef}
157-
controls
158-
preload="none"
159-
controlsList="nodownload nofullscreen noremoteplayback"
160-
style={{
161-
position: 'absolute',
162-
overflow: 'hidden',
163-
display: 'none',
164-
height: '0px',
165-
width: '0px',
166-
}}
167-
src={audioRef.current?.src}
168-
onError={(error) => {
169-
logger.error('Error fetching audio:', error);
170-
}}
171-
id={`audio-${messageId}`}
172-
autoPlay
173-
/>
174-
) : null}
175-
</>
176-
);
177-
}
178-
17987
export function ExternalTTS({ isLast, index, messageId, content, className }: TMessageAudio) {
18088
const localize = useLocalize();
18189
const playbackRate = useRecoilValue(store.playbackRate);

client/src/components/Audio/Voices.tsx

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,11 @@
11
import React from 'react';
22
import { useRecoilState } from 'recoil';
33
import type { Option } from '~/common';
4-
import { useLocalize, useTTSBrowser, useTTSEdge, useTTSExternal } from '~/hooks';
4+
import { useLocalize, useTTSBrowser, useTTSExternal } from '~/hooks';
55
import { Dropdown } from '~/components/ui';
66
import { logger } from '~/utils';
77
import store from '~/store';
88

9-
export function EdgeVoiceDropdown() {
10-
const localize = useLocalize();
11-
const { voices = [] } = useTTSEdge();
12-
const [voice, setVoice] = useRecoilState(store.voice);
13-
14-
const handleVoiceChange = (newValue?: string | Option) => {
15-
logger.log('Edge Voice changed:', newValue);
16-
const newVoice = typeof newValue === 'string' ? newValue : newValue?.value;
17-
if (newVoice != null) {
18-
return setVoice(newVoice.toString());
19-
}
20-
};
21-
22-
return (
23-
<div className="flex items-center justify-between">
24-
<div>{localize('com_nav_voice_select')}</div>
25-
<Dropdown
26-
key={`edge-voice-dropdown-${voices.length}`}
27-
value={voice ?? ''}
28-
options={voices}
29-
onChange={handleVoiceChange}
30-
sizeClasses="min-w-[200px] !max-w-[400px] [--anchor-max-width:400px]"
31-
testId="EdgeVoiceDropdown"
32-
/>
33-
</div>
34-
);
35-
}
36-
379
export function BrowserVoiceDropdown() {
3810
const localize = useLocalize();
3911
const { voices = [] } = useTTSBrowser();

client/src/components/Chat/Messages/MessageAudio.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { memo } from 'react';
22
import { useRecoilValue } from 'recoil';
33
import type { TMessageAudio } from '~/common';
4-
import { BrowserTTS, EdgeTTS, ExternalTTS } from '~/components/Audio/TTS';
4+
import { BrowserTTS, ExternalTTS } from '~/components/Audio/TTS';
55
import { TTSEndpoints } from '~/common';
66
import store from '~/store';
77

88
function MessageAudio(props: TMessageAudio) {
99
const engineTTS = useRecoilValue<string>(store.engineTTS);
1010

1111
const TTSComponents = {
12-
[TTSEndpoints.edge]: EdgeTTS,
1312
[TTSEndpoints.browser]: BrowserTTS,
1413
[TTSEndpoints.external]: ExternalTTS,
1514
};

client/src/components/Nav/SettingsTabs/Speech/TTS/EngineTTSDropdown.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,9 @@ const EngineTTSDropdown: React.FC<EngineTTSDropdownProps> = ({ external }) => {
1515
const endpointOptions = external
1616
? [
1717
{ value: 'browser', label: localize('com_nav_browser') },
18-
{ value: 'edge', label: localize('com_nav_edge') },
1918
{ value: 'external', label: localize('com_nav_external') },
2019
]
21-
: [
22-
{ value: 'browser', label: localize('com_nav_browser') },
23-
{ value: 'edge', label: localize('com_nav_edge') },
24-
];
20+
: [{ value: 'browser', label: localize('com_nav_browser') }];
2521

2622
const handleSelect = (value: string) => {
2723
setEngineTTS(value);

client/src/components/Nav/SettingsTabs/Speech/TTS/VoiceDropdown.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import { useRecoilValue } from 'recoil';
2-
import {
3-
EdgeVoiceDropdown,
4-
BrowserVoiceDropdown,
5-
ExternalVoiceDropdown,
6-
} from '~/components/Audio/Voices';
2+
import { BrowserVoiceDropdown, ExternalVoiceDropdown } from '~/components/Audio/Voices';
73
import store from '~/store';
84
import { TTSEndpoints } from '~/common';
95

106
const voiceDropdownComponentsMap = {
11-
[TTSEndpoints.edge]: EdgeVoiceDropdown,
127
[TTSEndpoints.browser]: BrowserVoiceDropdown,
138
[TTSEndpoints.external]: ExternalVoiceDropdown,
149
};

client/src/hooks/Audio/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ export { default as useCustomAudioRef } from './useCustomAudioRef';
33
export { default as usePauseGlobalAudio } from './usePauseGlobalAudio';
44
export { default as useTTSExternal } from './useTTSExternal';
55
export { default as useTTSBrowser } from './useTTSBrowser';
6-
export { default as useTTSEdge } from './useTTSEdge';

client/src/hooks/Audio/useTTSEdge.ts

Lines changed: 0 additions & 100 deletions
This file was deleted.

client/src/hooks/Input/useTextToSpeech.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type { Option } from '~/common';
66
import useTextToSpeechExternal from '~/hooks/Input/useTextToSpeechExternal';
77
import useTextToSpeechBrowser from '~/hooks/Input/useTextToSpeechBrowser';
88
import useGetAudioSettings from '~/hooks/Input/useGetAudioSettings';
9-
import useTextToSpeechEdge from '~/hooks/Input/useTextToSpeechEdge';
109
import useAudioRef from '~/hooks/Audio/useAudioRef';
1110
import { usePauseGlobalAudio } from '../Audio';
1211
import { logger } from '~/utils';
@@ -40,12 +39,6 @@ const useTextToSpeech = (props?: TUseTextToSpeech) => {
4039
voices: voicesLocal,
4140
} = useTextToSpeechBrowser({ setIsSpeaking });
4241

43-
const {
44-
generateSpeechEdge,
45-
cancelSpeechEdge,
46-
voices: voicesEdge,
47-
} = useTextToSpeechEdge({ setIsSpeaking });
48-
4942
const {
5043
generateSpeechExternal,
5144
cancelSpeech: cancelSpeechExternal,
@@ -61,26 +54,23 @@ const useTextToSpeech = (props?: TUseTextToSpeech) => {
6154

6255
const generateSpeech = useMemo(() => {
6356
const map = {
64-
edge: generateSpeechEdge,
6557
browser: generateSpeechLocal,
6658
external: generateSpeechExternal,
6759
};
6860

6961
return map[textToSpeechEndpoint];
70-
}, [generateSpeechEdge, generateSpeechExternal, generateSpeechLocal, textToSpeechEndpoint]);
62+
}, [generateSpeechExternal, generateSpeechLocal, textToSpeechEndpoint]);
7163

7264
const cancelSpeech = useMemo(() => {
7365
const map = {
74-
edge: cancelSpeechEdge,
7566
browser: cancelSpeechLocal,
7667
external: cancelSpeechExternal,
7768
};
7869
return map[textToSpeechEndpoint];
79-
}, [cancelSpeechEdge, cancelSpeechExternal, cancelSpeechLocal, textToSpeechEndpoint]);
70+
}, [cancelSpeechExternal, cancelSpeechLocal, textToSpeechEndpoint]);
8071

8172
const isLoading = useMemo(() => {
8273
const map = {
83-
edge: false,
8474
browser: false,
8575
external: isLoadingExternal,
8676
};
@@ -89,13 +79,12 @@ const useTextToSpeech = (props?: TUseTextToSpeech) => {
8979

9080
const voices: Option[] | string[] = useMemo(() => {
9181
const voiceMap = {
92-
edge: voicesEdge,
9382
browser: voicesLocal,
9483
external: voicesExternal,
9584
};
9685

9786
return voiceMap[textToSpeechEndpoint];
98-
}, [textToSpeechEndpoint, voicesEdge, voicesExternal, voicesLocal]);
87+
}, [textToSpeechEndpoint, voicesExternal, voicesLocal]);
9988

10089
useEffect(() => {
10190
const firstVoice = voices[0];

0 commit comments

Comments
 (0)