generateSpeech static method
Generate speech from provided text and save audio to the provided file path.
If Speech generation fails, it throws an Exception.
Implementation
static Future<void> generateSpeech(
String accessToken, String text, String filePath) async {
final data = {
"inputs": text,
"options": {"wait_for_model": true}
};
try {
final response = await _dio.post("/models/facebook/mms-tts-yor",
data: data,
options: Options(
headers: {"Authorization": "Bearer $accessToken"},
responseType: ResponseType.bytes));
if (response.statusCode == HttpStatus.ok) {
_saveBytesToFile(response.data, filePath);
} else {
throw Exception(response.statusMessage);
}
} catch (e) {
rethrow;
}
}