Skip to content

Commit

Permalink
fix: audio error message
Browse files Browse the repository at this point in the history
  • Loading branch information
hibig committed Dec 3, 2024
1 parent 83294ab commit 20f8097
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 17 deletions.
2 changes: 1 addition & 1 deletion config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const isProduction = env === 'production';
const t = Date.now();
export default defineConfig({
proxy: {
...proxy('http://192.168.50.4')
...proxy('http://192.168.50.3')
},
history: {
type: 'hash'
Expand Down
10 changes: 8 additions & 2 deletions src/components/audio-animation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import './index.less';
interface AudioAnimationProps {
width: number;
height: number;
maxWidth?: number;
scaleFactor?: number;
maxBarCount?: number;
fixedHeight?: boolean;
Expand All @@ -18,6 +19,7 @@ const AudioAnimation: React.FC<AudioAnimationProps> = (props) => {
const {
scaleFactor = 1.2,
maxBarCount = 128,
maxWidth,
fixedHeight = true,
analyserData,
width: initialWidth,
Expand Down Expand Up @@ -133,12 +135,16 @@ const AudioAnimation: React.FC<AudioAnimationProps> = (props) => {

React.useEffect(() => {
if (size) {
setWidth(size?.width || 0);
if (maxWidth) {
setWidth(Math.min(size.width, maxWidth));
} else {
setWidth(size?.width || 0);
}
if (!fixedHeight) {
setHeight(size?.height || 0);
}
}
}, [size]);
}, [size, maxWidth]);

useEffect(() => {
if (!canvasRef.current) return;
Expand Down
1 change: 1 addition & 0 deletions src/components/logs-viewer/virtual-log-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ const LogsViewer: React.FC<LogsViewerProps> = forwardRef((props, ref) => {

const updateContent = useCallback(
(inputStr: string) => {
console.log('inputStr===', inputStr);
const data = inputStr.replace(replaceLineRegex, '\n');
if (isClean(data)) {
cacheDataRef.current = data;
Expand Down
5 changes: 5 additions & 0 deletions src/components/speech-content/speech-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ const SpeechItem: React.FC<SpeechContentProps> = (props) => {
debounceSeek(value);
};

const handlOnChangeComplete = useCallback((value: number) => {
ref.current?.seekTo(value / duration);
setCurrentTime(value);
}, []);

const onDownload = useCallback(() => {
const url = props.audioUrl || '';
const filename = `audio-${dayjs().format('YYYYMMDDHHmmss')}.${props.format}`;
Expand Down
8 changes: 7 additions & 1 deletion src/constants/external-links.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
export default {
const externalLinks = {
documentation: 'https://docs.gpustack.ai/',
github: 'https://github.com/gpustack/gpustack',
discord: 'https://discord.gg/VXYJzuaqwD',
site: 'https://gpustack.ai/',
release: 'https://github.com/gpustack/gpustack/releases'
};

export default externalLinks;

export const externalRefer = {
audioPermission: `${externalLinks.documentation}latest/user-guide/playground/#audio-playground`
};
1 change: 1 addition & 0 deletions src/locales/en-US/playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export default {
'Upload an audio file or start recording',
'playground.audio.enablemic':
"Enable microphone access in your browser's settings.",
'playground.audio.enablemic.doc': 'Refer to',
'playground.audio.startrecord': 'Start Recording',
'playground.audio.stoprecord': 'Stop Recording',
'playground.audio.generating.tips': 'Generated text will appear here.',
Expand Down
1 change: 1 addition & 0 deletions src/locales/zh-CN/playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export default {
'playground.audio.texttospeech.tips': '生成的语音将出现在这里',
'playground.audio.speechtotext.tips': '上传音频文件或开始录音',
'playground.audio.enablemic': '请允许浏览器访问麦克风,以便开始录音',
'playground.audio.enablemic.doc': '参考文档',
'playground.audio.startrecord': '开始录音',
'playground.audio.stoprecord': '停止录音',
'playground.audio.generating.tips': '生成的文本将出现在这里',
Expand Down
21 changes: 20 additions & 1 deletion src/pages/playground/components/audio-input.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { externalRefer } from '@/constants/external-links';
import { AudioOutlined } from '@ant-design/icons';
import { useIntl } from '@umijs/max';
import { Button, Space, Tooltip } from 'antd';
Expand Down Expand Up @@ -215,7 +216,25 @@ const AudioInput: React.FC<AudioInputProps> = (props) => {

const renderRecordButtonTips = useMemo(() => {
if (!audioPermission) {
return intl.formatMessage({ id: 'playground.audio.enablemic' });
return (
<span>
<span>
{intl.formatMessage({ id: 'playground.audio.enablemic' })}
<Button
size="small"
color="primary"
variant="link"
href={`${externalRefer.audioPermission}`}
target="_blank"
style={{
color: 'var(--ant-blue-5)'
}}
>
{intl.formatMessage({ id: 'playground.audio.enablemic.doc' })}
</Button>
</span>
</span>
);
}
return isRecording
? intl.formatMessage({ id: 'playground.audio.stoprecord' })
Expand Down
3 changes: 2 additions & 1 deletion src/pages/playground/components/ground-stt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
}
);

if (result?.status_code !== 200) {
if (result?.status_code && result?.status_code !== 200) {
setTokenResult({
error: true,
errorMessage:
Expand Down Expand Up @@ -211,6 +211,7 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
setIsRecording(val);
setAudioData(null);
setTokenResult(null);
setMessageList([]);
console.log('data===', val);
}, []);

Expand Down
12 changes: 1 addition & 11 deletions src/pages/playground/components/ground-tts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,7 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
autoplay: boolean;
audioUrl: string;
}[]
>([
{
input: '',
voice: '',
format: '',
speed: 0,
uid: 0,
autoplay: false,
audioUrl: ''
}
]);
>([]);
const locale = getLocale();
const intl = useIntl();
const [searchParams] = useSearchParams();
Expand Down

0 comments on commit 20f8097

Please sign in to comment.