transcribeAudio method
Future<TranscriptionResult>
transcribeAudio({
- required String audioFile,
- String? language,
- TranscriptionOptions? options,
Performs audio transcription
audioFile - path or URL to audio file
language - audio language (optional)
options - additional transcription options
@deprecated Use transcribeFile instead of this method
Implementation
Future<TranscriptionResult> transcribeAudio({
required String audioFile,
String? language,
TranscriptionOptions? options,
}) async {
try {
// Check if audioFile is URL or path to file
if (audioFile.startsWith('http')) {
// If it's URL, initiate transcription and wait for result
final transcriptionInit = await initiateTranscription(
audioUrl: audioFile,
language: language,
options: options,
);
// Wait for result (5 attempts with 2 seconds interval)
int attempts = 0;
while (attempts < 5) {
try {
return await getTranscriptionResult(transcriptionInit.resultUrl);
} on GladiaApiException catch (e) {
if (e.statusCode == 202) {
await Future.delayed(const Duration(seconds: 2));
attempts++;
} else {
rethrow;
}
}
}
throw GladiaApiException(
message: 'Maximum waiting time for transcription result exceeded',
statusCode: 408,
);
} else {
// If it's path to file, use transcribeFile
final file = File(audioFile);
if (!file.existsSync()) {
throw GladiaApiException(
message: 'File not found: $audioFile',
statusCode: 404,
);
}
final result = await transcribeFile(
file: file,
language: language,
options: options,
);
return result as TranscriptionResult;
}
} catch (e) {
if (e is GladiaApiException) {
rethrow;
}
throw GladiaApiException(message: e.toString());
}
}