translateAudio static method
Translates the audio file at the given file path to text
Implementation
static Future<(GroqAudioResponse, GroqRateLimitInformation)> translateAudio({
required String apiKey,
required String filePath,
required String modelId,
required double temperature,
}) async {
var request =
http.MultipartRequest('POST', Uri.parse(_getAudioTranslationUrl));
request.headers['Authorization'] = 'Bearer $apiKey';
request.headers['Content-Type'] = 'multipart/form-data';
request.files.add(await http.MultipartFile.fromPath('file', filePath));
request.fields['model'] = modelId;
request.fields['temperature'] = temperature.toString();
var response = await request.send();
final responseBody = await response.stream.bytesToString();
final jsonBody = json.decode(responseBody);
if (response.statusCode == 200) {
final audioResponse = GroqParser.audioResponseFromJson(jsonBody);
final rateLimitInfo =
GroqParser.rateLimitInformationFromHeaders(response.headers);
return (audioResponse, rateLimitInfo);
} else {
throw GroqException(
statusCode: response.statusCode, error: GroqError.fromJson(jsonBody));
}
}