callApiForVoice method

Future<Uint8List> callApiForVoice(
  1. dynamic voiceLabel
)

Implementation

Future<Uint8List> callApiForVoice(dynamic voiceLabel) async {
  final String url = 'https://services-stage.haiva.ai/v1/speech/text-to-speech';
  final language = 'en-US';
  final text = "Hello! from HAIVA. I'm a AI powered Multilingual Voice agent.";

  final requestBody = {
    "language": language,
    "text": text,
    "voice": voiceLabel
  };

  final response = await http.post(
    Uri.parse(url),
    headers: {
      "Content-Type": "application/json",
    },
    body: jsonEncode(requestBody),
  );
  if (response.statusCode == 200) {
    print('Voice Response${response.bodyBytes}');
    return response.bodyBytes;
  } else {
    throw Exception('Failed to convert text to speech');
  }
}