speechToText method
Convert speech to text with full configuration support
Throws UnsupportedError if not supported. Check supportedFeatures first.
Implementation
@override
Future<STTResponse> speechToText(STTRequest request) async {
late ElevenLabsSTTResponse response;
if (request.audioData != null) {
response = await _speechToTextInternal(
Uint8List.fromList(request.audioData!),
model: request.model,
languageCode: request.language,
tagAudioEvents: request.tagAudioEvents,
numSpeakers: request.numSpeakers,
timestampsGranularity: request.timestampGranularity.name,
diarize: request.diarize,
fileFormat: request.format,
enableLogging: request.enableLogging,
);
} else if (request.filePath != null) {
response = await _speechToTextFromFileInternal(
request.filePath!,
model: request.model,
languageCode: request.language,
tagAudioEvents: request.tagAudioEvents,
numSpeakers: request.numSpeakers,
timestampsGranularity: request.timestampGranularity.name,
diarize: request.diarize,
fileFormat: request.format,
enableLogging: request.enableLogging,
);
} else {
throw const InvalidRequestError(
'Either audioData or filePath must be provided');
}
return STTResponse(
text: response.text,
language: response.languageCode,
confidence: response.languageProbability,
words: response.words
?.map((w) => WordTiming(
word: w.text,
start: w.start,
end: w.end,
confidence:
null, // ElevenLabs doesn't provide word-level confidence
))
.toList(),
model: request.model,
duration: null,
usage: null,
additionalFormats: response.additionalFormats,
);
}