- Python
- TypeScript
def stt_transcribe(client: Cartesia) -> None:
"""Transcribe audio with word timestamps."""
with open("audio.wav", "rb") as f:
response = client.stt.transcribe(
file=f,
model="ink-whisper",
language="en",
timestamp_granularities=["word"], # Optional: get word timestamps
)
print(response.text)
if response.words:
for word in response.words:
print(f"{word.word}: {word.start}s - {word.end}s")
async function sttTranscribe(client: Cartesia): Promise<void> {
/** Transcribe audio with word timestamps. */
const file = fs.createReadStream('audio.wav');
const response = await client.stt.transcribe({
file,
model: 'ink-whisper',
language: 'en',
timestamp_granularities: ['word'],
});
console.log(response.text);
if (response.words) {
for (const word of response.words) {
console.log(`${word.word}: ${word.start}s - ${word.end}s`);
}
}
}
Run this example
- Python
- TypeScript
cd cartesia-python
CARTESIA_API_KEY=YOUR_KEY python3 examples/examples.py stt_transcribe
cd cartesia-js
CARTESIA_API_KEY=YOUR_KEY npx ts-node examples/node_examples.ts sttTranscribe