createHistoryAudioId method
Future<File>
createHistoryAudioId(
{ - required dynamic itemId,
- dynamic fileName,
})
Implementation
Future<File> createHistoryAudioId({
required itemId,
fileName,
}) async {
Map<String, String> headers = {
'xi-api-key': ElevenLabs.apiKey,
'accept': 'audio/mpeg',
};
try {
final dir = await getTemporaryDirectory();
final file =
File('${dir.path}/${fileName?.replaceAll(RegExp(r"\s+"), "")}.mp3');
if (await file.exists()) {
return file;
} else {
final response = await ElevenLabsEndpoints.client.get(
Uri.parse("${ElevenLabsEndpoints.historyUrl}/$itemId/audio"),
headers: headers,
);
String id = DateTime.now().millisecondsSinceEpoch.toString();
final file = fileName?.replaceAll(RegExp(r"\s+"), "") != null
? File(
'${dir.path}/${fileName?.replaceAll(RegExp(r"\s+"), "")}.mp3')
: File('${dir.path}/$id.mp3');
final bytes = response.bodyBytes;
await file.writeAsBytes(bytes);
return file;
}
} catch (e) {
throw (e);
}
}