Skip to content

Commit

Permalink
fix: add lang dependence for voice wave component
Browse files Browse the repository at this point in the history
  • Loading branch information
Viskeyy authored and fanweixiao committed Feb 22, 2024
1 parent 34c609d commit b1f86ad
Showing 1 changed file with 30 additions and 27 deletions.
57 changes: 30 additions & 27 deletions src/components/VoiceWaves/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,35 @@ export const VoiceWaves = observer(
},
}));

const uploadAudio = useCallback(async (blob) => {
if (blob.size === 0) {
return;
}
// console.log('uploadAudio=>', blob);
const dlUrl = URL.createObjectURL(blob).split('/');
const filename = `${dlUrl[3]}.m4a`;
const file = new File([blob], filename);
const formData = new FormData();
formData.append('file', file);
try {
const response = await fetch(`${API_ENDPOINT}/transcribe?lang=${lang || 'en'}`, {
// const response = await fetch('http://1.13.101.86:8000/test', {
method: 'POST',
// headers: {
// 'Content-Type': 'multipart/form-data',
// },
body: formData,
});
const data = await response.json();
onText?.(data, isTranscribingRef.current);
// console.log('data=>', data);
} catch (error) {
console.error('error=>', error);
}
}, []);
const uploadAudio = useCallback(
async (blob) => {
if (blob.size === 0) {
return;
}
// console.log('uploadAudio=>', blob);
const dlUrl = URL.createObjectURL(blob).split('/');
const filename = `${dlUrl[3]}.m4a`;
const file = new File([blob], filename);
const formData = new FormData();
formData.append('file', file);
try {
const response = await fetch(`${API_ENDPOINT}/transcribe?lang=${lang || 'en'}`, {
// const response = await fetch('http://1.13.101.86:8000/test', {
method: 'POST',
// headers: {
// 'Content-Type': 'multipart/form-data',
// },
body: formData,
});
const data = await response.json();
onText?.(data, isTranscribingRef.current);
// console.log('data=>', data);
} catch (error) {
console.error('error=>', error);
}
},
[lang],
);

const getDevices = useCallback(() => {
RecordPlugin.getAvailableAudioDevices().then((devices) => {
Expand Down Expand Up @@ -113,7 +116,7 @@ export const VoiceWaves = observer(
checkVolumeRef.current && clearInterval(checkVolumeRef.current);
durationTimerRef.current && clearInterval(durationTimerRef.current);
};
}, []);
}, [lang]);

useEffect(() => {
if (store.isRecording) {
Expand Down

0 comments on commit b1f86ad

Please sign in to comment.