React
Audio
Hooks for speech-to-text and text-to-speech.
Audio Hooks
See it in action
Try Voice Notes and Meeting Assistant for working demos of these hooks.
useTranscribe
Transcribe audio to text (speech-to-text).
import { useTranscribe } from '@localmode/react';
import { transformers } from '@localmode/transformers';
const model = transformers.speechToText('onnx-community/whisper-tiny.en');
function Demo() {
const { data, isLoading, execute } = useTranscribe({ model });
const handleFile = (file: File) => execute(file);
return (
<div>
<input type="file" accept="audio/*" onChange={(e) => {
if (e.target.files?.[0]) handleFile(e.target.files[0]);
}} />
{isLoading && <p>Transcribing...</p>}
{data && <p>{data.text}</p>}
</div>
);
}useSynthesizeSpeech
Generate speech audio from text (text-to-speech).
import { useSynthesizeSpeech } from '@localmode/react';
const { data, isLoading, execute } = useSynthesizeSpeech({ model });
await execute('Hello world');
// data.audio = Float32Array, data.sampleRate = 16000For model recommendations, see the Transformers Audio guide.