fix: error message do not show in tts
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { pcmToWav } from '@/utils/pcm-to-wav';
|
||||
import { useCallback, useRef, useState } from 'react';
|
||||
import { useMemoizedFn } from 'ahooks';
|
||||
import { useRef, useState } from 'react';
|
||||
import { textToSpeech } from '../../apis';
|
||||
import { extractErrorMessage } from '../../config';
|
||||
|
||||
@@ -51,8 +52,7 @@ export const useNonStreamTTS = (params?: UseNonStreamTTSParams) => {
|
||||
);
|
||||
};
|
||||
|
||||
const generate = useCallback(
|
||||
async (ttsParams: TTSParams) => {
|
||||
const generate = useMemoizedFn(async (ttsParams: TTSParams) => {
|
||||
try {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
@@ -66,8 +66,7 @@ export const useNonStreamTTS = (params?: UseNonStreamTTSParams) => {
|
||||
data: ttsParams,
|
||||
signal
|
||||
});
|
||||
|
||||
if ((res?.status_code && res?.status_code !== 200) || res?.error) {
|
||||
if (!res?.audioBlob || res?.error) {
|
||||
const errorMessage = extractErrorMessage(res);
|
||||
setError({
|
||||
error: true,
|
||||
@@ -99,6 +98,7 @@ export const useNonStreamTTS = (params?: UseNonStreamTTSParams) => {
|
||||
params?.onSuccess?.(result);
|
||||
return res;
|
||||
} catch (err: any) {
|
||||
console.log('TTS error', err);
|
||||
const res = err?.response?.data;
|
||||
if (res?.error) {
|
||||
const errorMessage = extractErrorMessage(res);
|
||||
@@ -112,14 +112,12 @@ export const useNonStreamTTS = (params?: UseNonStreamTTSParams) => {
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
},
|
||||
[params]
|
||||
);
|
||||
});
|
||||
|
||||
const abort = useCallback(() => {
|
||||
const abort = useMemoizedFn(() => {
|
||||
controllerRef.current?.abort();
|
||||
setLoading(false);
|
||||
}, []);
|
||||
});
|
||||
|
||||
return {
|
||||
generate,
|
||||
|
||||
@@ -224,6 +224,7 @@ const GroundTTS: React.FC<MessageProps> = forwardRef((props, ref) => {
|
||||
}
|
||||
} catch (error: any) {
|
||||
setPlayingStream(false);
|
||||
console.error('Error generating TTS:', error);
|
||||
setTokenResult({
|
||||
error: true,
|
||||
errorMessage: error?.message || 'Unknown error'
|
||||
|
||||
Reference in New Issue
Block a user