Skip to content

Commit

Permalink
feat: 语音选择
Browse files Browse the repository at this point in the history
  • Loading branch information
DDMeaqua committed Oct 14, 2024
1 parent 5e514c5 commit b91c224
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
6 changes: 4 additions & 2 deletions app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -558,10 +558,12 @@ export function ChatActions(props: {

useEffect(() => {
if (isFirefox()) config.sttConfig.engine = FIREFOX_DEFAULT_STT_ENGINE;
const lang = config.sttConfig.lang;
setSpeechApi(
config.sttConfig.engine !== DEFAULT_STT_ENGINE
? new WebTranscriptionApi((transcription) =>
onRecognitionEnd(transcription),
? new WebTranscriptionApi(
(transcription) => onRecognitionEnd(transcription),
lang,
)
: new OpenAITranscriptionApi((transcription) =>
onRecognitionEnd(transcription),
Expand Down
4 changes: 2 additions & 2 deletions app/components/stt-config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ export function STTConfigList(props: {
{props.sttConfig.engine === "Web Speech API" && !isFirefox() && (
<ListItem title="语言选择">
<Select
value={props.sttConfig.language}
value={props.sttConfig.lang}
onChange={(e) => {
props.updateConfig(
(config) => (config.language = e.currentTarget.value),
(config) => (config.lang = e.currentTarget.value),
);
}}
>
Expand Down
2 changes: 1 addition & 1 deletion app/store/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const DEFAULT_CONFIG = {
sttConfig: {
enable: true,
engine: DEFAULT_STT_ENGINE,
language: DEFAULT_STT_LANGUAGE,
lang: DEFAULT_STT_LANGUAGE,
},
};

Expand Down
4 changes: 2 additions & 2 deletions app/utils/speech.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class WebTranscriptionApi extends SpeechApi {

isListening = () => this.listeningStatus;

constructor(transcriptionCallback?: TranscriptionCallback) {
constructor(transcriptionCallback?: TranscriptionCallback, lang?: string) {
super();
if (isFirefox()) return;
const SpeechRecognition =
Expand All @@ -102,7 +102,7 @@ export class WebTranscriptionApi extends SpeechApi {
this.recognitionInstance = new SpeechRecognition();
this.recognitionInstance.continuous = true;
this.recognitionInstance.interimResults = true;
this.recognitionInstance.lang = getSTTLang();
this.recognitionInstance.lang = lang ?? getSTTLang();
if (transcriptionCallback) {
this.onTranscriptionReceived(transcriptionCallback);
}
Expand Down

0 comments on commit b91c224

Please sign in to comment.