Skip to content
19 changes: 19 additions & 0 deletions lib/src/amazon/audio/audio_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ class AudioClientAmazon extends BaseClient {

@override
Future<http.StreamedResponse> send(http.BaseRequest request) {
// Log initial request values
print('--- Amazon Polly Request ---');
print('URL: ${request.url}');
print('Method: ${request.method}');
print('Initial Headers: ${request.headers}');
print('Query Parameters: ${request.url.queryParameters}');
if (request is http.Request) {
print('Request Body: ${request.body}');
}

request.headers['Content-Type'] = "application/json";

final sigv4Client = Sigv4Client(
Expand All @@ -18,6 +28,8 @@ class AudioClientAmazon extends BaseClient {
serviceName: 'polly',
);

print('Region = ${ConfigAmazon.region}');

final headers = sigv4Client.signedHeaders(
request.url.toString(),
method: request.method,
Expand All @@ -26,8 +38,15 @@ class AudioClientAmazon extends BaseClient {
body: request is http.Request ? request.body : null,
);

// Log signed headers
print('Signed Headers: $headers');

request.headers.addAll(headers);

print('Final Headers After Merge: ${request.headers}');
print('------------------------------');

return client.send(request);
}

}
9 changes: 6 additions & 3 deletions lib/src/amazon/audio/audio_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ class AudioHandlerAmazon {
try {
final ssml =
SsmlAmazon(text: params.text, rate: params.rate, pitch: params.pitch);
print('Inisde = ${params.voice.isSsml}');

final Map<String, dynamic> body = {
'OutputFormat': params.audioFormat,
'Text': ssml.sanitizedSsml,
'TextType': 'ssml',
'Text': params.voice.isSsml=='ssml'?ssml.sanitizedSsml:params.text,
// 'TextType':params.voice.isSsml? 'ssml':'text',
'TextType':params.voice.isSsml,
'VoiceId': params.voice.code,
// 'Engine': params.voice.engines
'Engine': params.voice.engines.first
};

final String bodyJson = jsonEncode(body);
print('api = ${EndpointsAmazon.tts} body = ${jsonEncode(body)}');

final response = await audioClient.post(Uri.parse(EndpointsAmazon.tts),
body: bodyJson);
Expand Down
9 changes: 7 additions & 2 deletions lib/src/amazon/voices/voice_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,27 @@ class VoiceAmazon extends VoiceUniversal {
@JsonKey(name: "LanguageCode", fromJson: _toLocale, includeToJson: false)
VoiceLocale locale;


VoiceAmazon(
{this.provider = TtsProviders.amazon,
required this.engines,
required this.code,
required this.name,
required this.nativeName,
required this.gender,
required this.locale})
required this.locale,
String isSsml = 'ssml', // ✅ Add this
})
: super(
provider: provider,
engines: engines,
code: code,
name: name,
nativeName: nativeName,
gender: gender,
locale: locale);
locale: locale,
isSsml: isSsml, // ✅ Pass to base
);

factory VoiceAmazon.fromJson(Map<String, dynamic> json) =>
_$VoiceAmazonFromJson(json);
Expand Down
2 changes: 2 additions & 0 deletions lib/src/universal/tts/tts_params_mapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ class TtsParamsMapper {

static TtsParamsAmazon toAmazon(TtsParamsUniversal universalParams) {
return TtsParamsAmazon(

voice: VoiceAmazon(
engines: universalParams.voice.engines,
code: universalParams.voice.code,
name: universalParams.voice.name,
nativeName: universalParams.voice.nativeName,
gender: universalParams.voice.gender,
locale: universalParams.voice.locale,
isSsml: universalParams.voice.isSsml, // ✅ Add this
),
text: universalParams.text,
audioFormat:
Expand Down
25 changes: 25 additions & 0 deletions lib/src/universal/voices/voice_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,30 @@ class VoiceUniversal {
String gender;
VoiceLocale locale;

String isSsml;

VoiceUniversal copyWith({
String? provider,
List<String>? engines,
String? code,
String? name,
String? nativeName,
String? gender,
VoiceLocale? locale,
String? isSsml,
}) {
return VoiceUniversal(
provider: provider ?? this.provider,
engines: engines ?? List.from(this.engines),
code: code ?? this.code,
name: name ?? this.name,
nativeName: nativeName ?? this.nativeName,
gender: gender ?? this.gender,
locale: locale ?? this.locale,
isSsml: isSsml??this.isSsml,
);
}

VoiceUniversal({
required this.provider,
required this.engines,
Expand All @@ -17,5 +41,6 @@ class VoiceUniversal {
required this.nativeName,
required this.gender,
required this.locale,
this.isSsml='ssml',
});
}