sendAudiotoText method
Implementation
Future<String> sendAudiotoText(
String audioPath, {
String? prompt,
Map<String, dynamic>? extraOptions,
}) async {
final url = Uri.parse('https://api.openai.com/v1/audio/transcriptions');
var request = http.MultipartRequest('POST', url)
..headers['Authorization'] = 'Bearer $apiKey';
request.files.add(await http.MultipartFile.fromPath('file', audioPath));
if (extraOptions != null) {
extraOptions.forEach((key, value) {
request.fields[key] = value.toString();
});
}
final streamedResponse = await request.send();
final response = await http.Response.fromStream(streamedResponse);
if (response.statusCode == 200) {
return response.body;
} else {
throw APIException(
'OpenAI audio error: ${response.statusCode} ${response.body}',
statusCode: response.statusCode,
);
}
}