chore: voice language default value by current language
This commit is contained in:
+1
-1
@@ -14,7 +14,7 @@ const isProduction = env === 'production';
|
|||||||
const t = Date.now();
|
const t = Date.now();
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
proxy: {
|
proxy: {
|
||||||
...proxy('http://192.168.50.3')
|
...proxy('http://192.168.50.4')
|
||||||
},
|
},
|
||||||
history: {
|
history: {
|
||||||
type: 'hash'
|
type: 'hash'
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import SealSelect from '@/components/seal-form/seal-select';
|
|||||||
import SpeechContent from '@/components/speech-content';
|
import SpeechContent from '@/components/speech-content';
|
||||||
import useOverlayScroller from '@/hooks/use-overlay-scroller';
|
import useOverlayScroller from '@/hooks/use-overlay-scroller';
|
||||||
import { SendOutlined } from '@ant-design/icons';
|
import { SendOutlined } from '@ant-design/icons';
|
||||||
import { useIntl, useSearchParams } from '@umijs/max';
|
import { getLocale, useIntl, useSearchParams } from '@umijs/max';
|
||||||
import { Form, Spin } from 'antd';
|
import { Form, Spin } from 'antd';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
@@ -53,7 +53,7 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
audioUrl: string;
|
audioUrl: string;
|
||||||
}[]
|
}[]
|
||||||
>([]);
|
>([]);
|
||||||
|
const locale = getLocale();
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
const modelType = searchParams.get('type') || '';
|
const modelType = searchParams.get('type') || '';
|
||||||
@@ -72,7 +72,9 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
const messageListLengthCache = useRef<number>(0);
|
const messageListLengthCache = useRef<number>(0);
|
||||||
const checkvalueRef = useRef<any>(true);
|
const checkvalueRef = useRef<any>(true);
|
||||||
const [currentPrompt, setCurrentPrompt] = useState<string>('');
|
const [currentPrompt, setCurrentPrompt] = useState<string>('');
|
||||||
const [voiceList, setVoiceList] = useState<Global.BaseOption<string>[]>([]);
|
const [voiceDataList, setVoiceList] = useState<Global.BaseOption<string>[]>(
|
||||||
|
[]
|
||||||
|
);
|
||||||
const formRef = useRef<any>(null);
|
const formRef = useRef<any>(null);
|
||||||
|
|
||||||
const { initialize, updateScrollerPosition } = useOverlayScroller();
|
const { initialize, updateScrollerPosition } = useOverlayScroller();
|
||||||
@@ -90,6 +92,37 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const sortVoiceList = useCallback(
|
||||||
|
(locale: string, voiceDataList: Global.BaseOption<string>[]) => {
|
||||||
|
const lang = locale === 'en-US' ? 'english' : 'chinese';
|
||||||
|
|
||||||
|
const list = voiceDataList.sort((a, b) => {
|
||||||
|
const aContains = a.value.toLowerCase().includes(lang) ? 1 : 0;
|
||||||
|
const bContains = b.value.toLowerCase().includes(lang) ? 1 : 0;
|
||||||
|
return bContains - aContains;
|
||||||
|
});
|
||||||
|
return list;
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
|
const voiceList = useMemo(() => {
|
||||||
|
if (!voiceDataList.length) return [];
|
||||||
|
const newList = sortVoiceList(locale, voiceDataList);
|
||||||
|
return newList;
|
||||||
|
}, [locale, voiceDataList, sortVoiceList]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const newList = sortVoiceList(locale, voiceDataList);
|
||||||
|
setParams((pre: any) => {
|
||||||
|
return {
|
||||||
|
...pre,
|
||||||
|
voice: newList[0]?.value
|
||||||
|
};
|
||||||
|
});
|
||||||
|
formRef.current?.form.setFieldValue('voice', newList[0]?.value);
|
||||||
|
}, [locale, voiceDataList, sortVoiceList]);
|
||||||
|
|
||||||
const setMessageId = () => {
|
const setMessageId = () => {
|
||||||
messageId.current = messageId.current + 1;
|
messageId.current = messageId.current + 1;
|
||||||
};
|
};
|
||||||
@@ -192,21 +225,23 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
setVoiceList([]);
|
setVoiceList([]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const voiceList = _.map(res.voices || [], (item: any) => {
|
const list = _.map(res.voices || [], (item: any) => {
|
||||||
return {
|
return {
|
||||||
label: item,
|
label: item,
|
||||||
value: item
|
value: item
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
setVoiceList(voiceList);
|
const newList = sortVoiceList(locale, list);
|
||||||
|
|
||||||
|
setVoiceList(newList);
|
||||||
setParams((pre: any) => {
|
setParams((pre: any) => {
|
||||||
return {
|
return {
|
||||||
...pre,
|
...pre,
|
||||||
voice: voiceList[0]?.value
|
voice: newList[0]?.value
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
formRef.current?.form.setFieldValue('voice', voiceList[0]?.value);
|
formRef.current?.form.setFieldValue('voice', newList[0]?.value);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
const res = error?.response?.data;
|
const res = error?.response?.data;
|
||||||
if (res?.error) {
|
if (res?.error) {
|
||||||
@@ -216,7 +251,6 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
res?.error?.message || res?.data?.error || res.error?.detail || ''
|
res?.error?.message || res?.data?.error || res.error?.detail || ''
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
console.log('error:', error);
|
|
||||||
setVoiceList([]);
|
setVoiceList([]);
|
||||||
formRef.current?.form.setFieldValue('voice', '');
|
formRef.current?.form.setFieldValue('voice', '');
|
||||||
setParams((pre: any) => {
|
setParams((pre: any) => {
|
||||||
|
|||||||
@@ -86,7 +86,7 @@
|
|||||||
height: fit-content;
|
height: fit-content;
|
||||||
top: -10px;
|
top: -10px;
|
||||||
font-size: var(--font-size-middle);
|
font-size: var(--font-size-middle);
|
||||||
left: calc(50% + 14px);
|
left: calc(50% + 10px);
|
||||||
transform: translateX(-50%);
|
transform: translateX(-50%);
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user