|
|
@ -118,11 +118,53 @@ class _RecorderBottomSheetState extends State<RecorderBottomSheet> { |
|
|
|
|
|
|
|
|
final streamed = await request.send(); |
|
|
final streamed = await request.send(); |
|
|
final response = await http.Response.fromStream(streamed); |
|
|
final response = await http.Response.fromStream(streamed); |
|
|
if (streamed.statusCode < 200 || streamed.statusCode >= 300) { |
|
|
if (streamed.statusCode >= 200 && streamed.statusCode < 300) { |
|
|
|
|
|
final bodyText = utf8.decode(response.bodyBytes, allowMalformed: true); |
|
|
|
|
|
if (bodyText.isNotEmpty) { |
|
|
|
|
|
final decoded = jsonDecode(bodyText); |
|
|
|
|
|
|
|
|
|
|
|
String status = decoded['status'] ?? 'NotStarted'; |
|
|
|
|
|
final operationLocation = response.headers['operation-location']; |
|
|
|
|
|
int retryCount = 0; |
|
|
|
|
|
|
|
|
|
|
|
while (status != 'Succeeded' && status != 'Failed' && retryCount < 30) { |
|
|
|
|
|
await Future.delayed(const Duration(seconds: 1)); |
|
|
|
|
|
if (operationLocation != null && operationLocation.isNotEmpty) { |
|
|
|
|
|
status = await _operations(operationLocation); |
|
|
|
|
|
} else { |
|
|
|
|
|
final consentUrl = |
|
|
|
|
|
'https://$_resourceRegion.api.cognitive.microsoft.com/customvoice/consents/$_jessicaConsentId?api-version=2024-02-01-preview'; |
|
|
|
|
|
status = await _operations(consentUrl); |
|
|
|
|
|
} |
|
|
|
|
|
retryCount++; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (status != 'Succeeded') { |
|
|
|
|
|
throw Exception('Consent validation failed or timed out: $status'); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
throw Exception('Failed to create consent: ${response.statusCode}'); |
|
|
throw Exception('Failed to create consent: ${response.statusCode}'); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Future<String> _operations(String operationUrl) async { |
|
|
|
|
|
String status = 'NotStarted'; |
|
|
|
|
|
|
|
|
|
|
|
final url = Uri.parse(operationUrl); |
|
|
|
|
|
final response = await http.get(url, headers: { |
|
|
|
|
|
'Ocp-Apim-Subscription-Key': _resourceKey, |
|
|
|
|
|
}); |
|
|
|
|
|
if (response.statusCode == 200) { |
|
|
|
|
|
final bodyText = utf8.decode(response.bodyBytes, allowMalformed: true); |
|
|
|
|
|
if (bodyText.isNotEmpty) { |
|
|
|
|
|
final decoded = jsonDecode(bodyText); |
|
|
|
|
|
status = decoded['status'] ?? status; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return status; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
Future<void> _personalvoices() async { |
|
|
Future<void> _personalvoices() async { |
|
|
final url = Uri.parse( |
|
|
final url = Uri.parse( |
|
|
'https://$_resourceRegion.api.cognitive.microsoft.com/customvoice/personalvoices/$_jessicaPersonalVoiceId?api-version=2024-02-01-preview'); |
|
|
'https://$_resourceRegion.api.cognitive.microsoft.com/customvoice/personalvoices/$_jessicaPersonalVoiceId?api-version=2024-02-01-preview'); |
|
|
@ -133,8 +175,6 @@ class _RecorderBottomSheetState extends State<RecorderBottomSheet> { |
|
|
request.fields['consentId'] = _jessicaConsentId; |
|
|
request.fields['consentId'] = _jessicaConsentId; |
|
|
|
|
|
|
|
|
request.files.add(await http.MultipartFile.fromPath('audiodata', _path)); |
|
|
request.files.add(await http.MultipartFile.fromPath('audiodata', _path)); |
|
|
request.files.add(await http.MultipartFile.fromPath('audiodata', |
|
|
|
|
|
'/data/user/0/com.saitong.voitrans/app_flutter/VoiceReplication/recording_1764763812656.wav')); |
|
|
|
|
|
|
|
|
|
|
|
final streamed = await request.send(); |
|
|
final streamed = await request.send(); |
|
|
final response = await http.Response.fromStream(streamed); |
|
|
final response = await http.Response.fromStream(streamed); |
|
|
@ -142,17 +182,11 @@ class _RecorderBottomSheetState extends State<RecorderBottomSheet> { |
|
|
final bodyText = utf8.decode(response.bodyBytes, allowMalformed: true); |
|
|
final bodyText = utf8.decode(response.bodyBytes, allowMalformed: true); |
|
|
if (bodyText.isNotEmpty) { |
|
|
if (bodyText.isNotEmpty) { |
|
|
final decoded = jsonDecode(bodyText); |
|
|
final decoded = jsonDecode(bodyText); |
|
|
print('------2-------$decoded'); |
|
|
|
|
|
_controller.speakerProfileId.value = decoded['speakerProfileId']; |
|
|
_controller.speakerProfileId.value = decoded['speakerProfileId']; |
|
|
_storage.write('open_voice_replication', true); |
|
|
_storage.write('open_voice_replication', true); |
|
|
_storage.write('speakerProfileId', decoded['speakerProfileId']); |
|
|
_storage.write('speakerProfileId', decoded['speakerProfileId']); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
final bodyText = utf8.decode(response.bodyBytes, allowMalformed: true); |
|
|
|
|
|
if (bodyText.isNotEmpty) { |
|
|
|
|
|
final decoded = jsonDecode(bodyText); |
|
|
|
|
|
print('------2-------$decoded'); |
|
|
|
|
|
} |
|
|
|
|
|
throw Exception( |
|
|
throw Exception( |
|
|
'Failed to create personal voice: ${response.statusCode}'); |
|
|
'Failed to create personal voice: ${response.statusCode}'); |
|
|
} |
|
|
} |
|
|
|