matt HOFFNER
commited on
Commit
·
a98ce53
1
Parent(s):
a29c498
match filereader from example
Browse files- app/input.tsx +18 -13
app/input.tsx
CHANGED
|
@@ -50,11 +50,6 @@ const VoiceInputForm: React.FC<VoiceInputFormProps> = ({ handleSubmit, input, se
|
|
| 50 |
const [recognizedText, setRecognizedText] = useState('');
|
| 51 |
const transcriber = useTranscriber();
|
| 52 |
|
| 53 |
-
const onFormSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
| 54 |
-
e.preventDefault();
|
| 55 |
-
handleSubmit(input); // Assuming handleSubmit now takes the input as an argument
|
| 56 |
-
};
|
| 57 |
-
|
| 58 |
const startListening = useCallback((audioData: any) => {
|
| 59 |
transcriber.start(audioData);
|
| 60 |
}, [transcriber]);
|
|
@@ -98,17 +93,21 @@ const VoiceInputForm: React.FC<VoiceInputFormProps> = ({ handleSubmit, input, se
|
|
| 98 |
useEffect(() => {
|
| 99 |
const processRecording = async () => {
|
| 100 |
if (recordedBlob) {
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
}
|
| 108 |
};
|
| 109 |
-
|
| 110 |
processRecording();
|
| 111 |
-
}, [recordedBlob, startListening]);
|
| 112 |
|
| 113 |
const vad = useMicVAD({
|
| 114 |
modelURL: "/_next/static/chunks/silero_vad.onnx",
|
|
@@ -227,6 +226,12 @@ const VoiceInputForm: React.FC<VoiceInputFormProps> = ({ handleSubmit, input, se
|
|
| 227 |
))}
|
| 228 |
</div>
|
| 229 |
)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
<form onSubmit={handleSubmit} className={styles.form}>
|
| 231 |
<input
|
| 232 |
type="text"
|
|
|
|
| 50 |
const [recognizedText, setRecognizedText] = useState('');
|
| 51 |
const transcriber = useTranscriber();
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
const startListening = useCallback((audioData: any) => {
|
| 54 |
transcriber.start(audioData);
|
| 55 |
}, [transcriber]);
|
|
|
|
| 93 |
useEffect(() => {
|
| 94 |
const processRecording = async () => {
|
| 95 |
if (recordedBlob) {
|
| 96 |
+
const fileReader = new FileReader();
|
| 97 |
+
|
| 98 |
+
fileReader.onloadend = async () => {
|
| 99 |
+
const audioCTX = new AudioContext();
|
| 100 |
+
const arrayBuffer = fileReader.result as ArrayBuffer;
|
| 101 |
+
const decoded = await audioCTX.decodeAudioData(arrayBuffer);
|
| 102 |
+
startListening(decoded);
|
| 103 |
+
};
|
| 104 |
+
|
| 105 |
+
fileReader.readAsArrayBuffer(recordedBlob);
|
| 106 |
}
|
| 107 |
};
|
| 108 |
+
|
| 109 |
processRecording();
|
| 110 |
+
}, [recordedBlob, startListening]);
|
| 111 |
|
| 112 |
const vad = useMicVAD({
|
| 113 |
modelURL: "/_next/static/chunks/silero_vad.onnx",
|
|
|
|
| 226 |
))}
|
| 227 |
</div>
|
| 228 |
)}
|
| 229 |
+
{recordedBlob && (
|
| 230 |
+
<audio controls>
|
| 231 |
+
<source src={URL.createObjectURL(recordedBlob)} type={recordedBlob.type} />
|
| 232 |
+
Your browser does not support the audio element.
|
| 233 |
+
</audio>
|
| 234 |
+
)}
|
| 235 |
<form onSubmit={handleSubmit} className={styles.form}>
|
| 236 |
<input
|
| 237 |
type="text"
|