#FidelitasUniversity
I created this custom code for the application to work as a ChatGPT that reads the question and the answer
The code is:
Dependency: import 'package:flutter_tts/flutter_tts.dart';
Future<void> textToSpeech(String? myText, String? lang) async {
if (myText == null || myText.isEmpty) {
return;
}
FlutterTts flutterTts = FlutterTts();
// Verifica que el parámetro lang no esté vacío antes de establecer el idioma
if (lang != null && lang.isNotEmpty) {
flutterTts.setLanguage(lang);
} else {
// Si no se proporciona el idioma, establece el idioma predeterminado en inglés (en-US)
flutterTts.setLanguage("en-US");
}
String text = myText;
await flutterTts.speak(text);
}
The chatgpt api was added
The body:
{
"model": "gpt-3.5-turbo",
"messages": [
{
"role": "user",
"content": "<text>"
}
]
}
headers:
Authorization: Bearer OPENAI_API_KEY