Loading...
Loading...
> Speech-to-Text (STT) and Text-to-Speech (TTS) interfaces.
A dual-purpose voice interface for transcribing audio and generating speech. Features a real-time audio visualizer, multiple voice selections, and support for audio file uploads.
DESC: Add the voice tools to your page.
1import { Card, CardHeader, CardContent } from "@/components/ui/card";2import { Button } from "@/components/ui/button";3import { Textarea } from "@/components/ui/textarea";
Transcribe audio files using OpenAI Whisper.
1const handleTranscribe = async (audioFile: File) => {2 const formData = new FormData();3 formData.append('audio', audioFile);45 const response = await fetch('/api/ai/speech-to-text', {6 method: 'POST',7 body: formData,8 });9 const data = await response.json();10 return data.text; // Transcribed text11};
Generate speech using OpenAI TTS.
1const handleSpeak = async (text: string, voice: string) => {2 const response = await fetch('/api/ai/text-to-speech', {3 method: 'POST',4 headers: { 'Content-Type': 'application/json' },5 body: JSON.stringify({ text, voice }),6 });7 const blob = await response.blob();8 const url = URL.createObjectURL(blob);9 // Play or download the audio10 const audio = new Audio(url);11 audio.play();12};
| Option | Type | Default | Description |
|---|---|---|---|
| voice | "alloy" | "echo" | "fable" | "onyx" | "nova" | "shimmer" | "alloy" | OpenAI TTS voice selection. |
| audioFormats | string[] | ["mp3", "wav", "m4a", "webm"] | Supported input formats for STT. |
| maxFileSize | number | 25MB | Maximum audio file size for transcription. |