Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This expression has a type of 'void' so its value can't be used. Try checking to see if you're using the correct API; there might be a function or call that returns void you didn't expect. Also check type parameters and variables which might also be void. #19

Open
fanydhilah opened this issue Dec 5, 2020 · 0 comments

Comments

@fanydhilah
Copy link

hello, i am new in this flutter, and i wanna make chatbot app with stt and tts inside it. but i got error in this and i don;t khow what todo, please help me

`class _MyApppState extends State {
stt.SpeechToText _speech;
bool _isListening = false;
String _text = "";
String speak;
String qry;

@OverRide
void initState() {
super.initState();
_speech = stt.SpeechToText();
}

final FlutterTts flutterTts = FlutterTts();

void response(query) async {
AuthGoogle authGoogle =
await AuthGoogle(fileJson: "assets/newagent-kalbgl-c0fb323bfb4c.json")
.build();
Dialogflow dialogflow =
Dialogflow(authGoogle: authGoogle, language: Language.indonesian);
AIResponse aiResponse = await dialogflow.detectIntent(query);
setState(() {
messsages.insert(0, {
"data": 0,
"message": aiResponse.getListMessage()[0]["text"]["text"][0].toString()
});
});

print(aiResponse.getListMessage()[0]["text"]["text"][0].toString());

}

void _speak(query) async {
print(await flutterTts.getLanguages);
await flutterTts.setLanguage('jv-ID');
await flutterTts.speak(query);
}

final messageInsert = TextEditingController();
List messsages = List();

@OverRide
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
"Jawa Bot",
),
backgroundColor: Colors.blueGrey,
),
body: Container(
child: Column(children: [
Center(
child: Container(
padding: EdgeInsets.only(top: 15, bottom: 10),
child: Text(
"Dinten Niki, ${DateFormat("Hm").format(DateTime.now())}",
style: TextStyle(fontSize: 15),
),
),
),
Flexible(
child: ListView.builder(
reverse: true,
padding: EdgeInsets.all(10.0),
itemCount: messsages.length,
itemBuilder: (context, index) => chat(
messsages[index]["message"].toString(),
messsages[index]["data"]))),
SizedBox(
height: 20,
),
Divider(
height: 5.0,
color: Colors.greenAccent,
),
Container(
child: ListTile(
leading: IconButton(
icon: Icon(
_isListening ? Icons.mic : Icons.mic_none,
color: Colors.greenAccent,
size: 35,
),
onPressed: () {
_listen();
if (_text.isEmpty) {
print("empty message");
} else {
setState(() {
messsages.insert(0, {"data": 1, "message": _text});
});
speak = response(_text);
_speak(speak);
_text = '';
}
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus();
}
},
),
title: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(15)),
color: Color.fromRGBO(220, 220, 220, 1)),
padding: EdgeInsets.only(left: 15),
child: Row(
children: [
Flexible(
child: TextField(
controller: messageInsert,
decoration: InputDecoration(
hintText: "Send Your Message",
hintStyle: TextStyle(color: Colors.black26),
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
),
style: TextStyle(fontSize: 16, color: Colors.black),
)),
],
),
),
trailing: IconButton(
icon: Icon(Icons.send, size: 30, color: Colors.greenAccent),
onPressed: () {
if (messageInsert.text.isEmpty) {
print("empty message");
} else {
setState(() {
messsages.insert(
0, {"data": 1, "message": messageInsert.text});
});
response(messageInsert.text);
_speak(messageInsert.text);
messageInsert.clear();
}
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus();
}
}),
)),
SizedBox(
height: 15.0,
)
]),
));
}`

i wanna use tts for this text

`oid response(query) async {
AuthGoogle authGoogle =
await AuthGoogle(fileJson: "assets/newagent-kalbgl-c0fb323bfb4c.json")
.build();
Dialogflow dialogflow =
Dialogflow(authGoogle: authGoogle, language: Language.indonesian);
AIResponse aiResponse = await dialogflow.detectIntent(query);
setState(() {
messsages.insert(0, {
"data": 0,
"message": aiResponse.getListMessage()[0]["text"]["text"][0].toString()
});
});

print(aiResponse.getListMessage()[0]["text"]["text"][0].toString());

}

void _speak(query) async {
print(await flutterTts.getLanguages);
await flutterTts.setLanguage('jv-ID');
await flutterTts.speak(query);
}
`

and i put it like this

onPressed: () { _listen(); if (_text.isEmpty) { print("empty message"); } else { setState(() { messsages.insert(0, {"data": 1, "message": _text}); }); speak = response(_text); _speak(speak); _text = ''; } FocusScopeNode currentFocus = FocusScope.of(context); if (!currentFocus.hasPrimaryFocus) { currentFocus.unfocus(); } },

i don't know how to fix this, please help me, thankyou

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant