Я создаю чат-бота для моего последнего проекта года. Я использую Dialogflow для этого. Это идет довольно хорошо, но мой чат-бот не произносит заявления conv.ask, которые находятся в Fulfillment. Он просто повторяет ту же сущность, для которой я его использовал. Эти же операторы будут отображаться в веб-демонстрационной и тестовой консоли, представленной на веб-сайте Dialogflow, но не в моем приложении.
Это код выполнения
<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>const functions = require('firebase-functions');
const {dialogflow} = require('actions-on-google')
const Minerals_INTENT ='Mineral'
const Minerals_ENTITY ='Minerals'
const app = dialogflow()
app.intent( Minerals_INTENT , (conv) => {
const mineral_type = conv.parameters[Minerals_ENTITY];
if(mineral_type == "Calcium")
{
conv.ask("Sources: Green leafy vegetables, legumes, tofu, molasses,
sardines, okra, perch, trout, Chinese cabbage, rhubarb, sesame seeds")
}
else if(mineral_type == "Phosphorus")
{
conv.ask("Toxicity: Very rare. May result in soft tissue
calcification. \n Sources: Legumes, nuts, seeds, whole grains, eggs,
fish,
buckwheat, seafood, corn, wild rice")
}
else if(mineral_type == "Potassium")
{
conv.ask("Sources: Sweet potato, tomato, green leafy vegetables,
carrots,
prunes, beans, molasses, squash, fish, bananas, peaches, apricots, melon,
potatoes, dates, raisins, mushrooms")
}
})
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app)
Это мой текстовый или SSML-ответ
<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>$Minerals
Это код на странице чата моей Android Studio
<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>package com.example.ft.aidt;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.nfc.Tag;
import android.speech.tts.TextToSpeech;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.google.gson.JsonElement;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Map;
import ai.api.AIListener;
import ai.api.android.AIConfiguration;
import ai.api.android.AIService;
import ai.api.model.AIError;
import ai.api.model.AIResponse;
import ai.api.model.Result;
import ai.api.ui.AIDialog;
public class ai extends AppCompatActivity implements AIListener {
public static final String TAG = ai.class.getName();
private Button bu,nu;
private TextView resp;
private AIService aiService;
private TextView a;
private ImageView yu;
private TextToSpeech joi;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ai);
yu = (ImageView) findViewById(R.id.imageView20);
int permi =
ContextCompat.checkSelfPermission(this,Manifest.permission.RECORD_AUDIO);
if(permi != PackageManager.PERMISSION_GRANTED)
{
Toast.makeText(this, "Permission Denied",
Toast.LENGTH_SHORT).show();
MakeRequest();
}
final AIConfiguration config = new
AIConfiguration("b0369e8530c14cc0990cccab8b9f0289",
AIConfiguration.SupportedLanguages.English,
AIConfiguration.RecognitionEngine.System);
aiService = AIService.getService(this, config);
aiService.setListener(this);
bu =(Button) findViewById(R.id.button12);
resp=(TextView) findViewById(R.id.textView10);
a = (TextView) findViewById(R.id.textView12);
joi = new TextToSpeech(ai.this, new TextToSpeech.OnInitListener()
{
@Override
public void onInit(int status) {
}
});
yu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(ai.this,"Here you can talk to AIDT and converse
with it. If you fail to get a reply, please check your internet
connection.",Toast.LENGTH_LONG).show();
}
});
bu.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
resp.setText("ERROR");
return false;
}
});
bu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
aiService.startListening();
}
});
}
protected void MakeRequest() {
ActivityCompat.requestPermissions(this, new String[]
{Manifest.permission.RECORD_AUDIO},007);
}
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[]
grantResults) {
switch (requestCode) {
case 007: {
if (grantResults.length == 0
|| grantResults[0] !=
PackageManager.PERMISSION_GRANTED) {
} else {
}
return;
}}}
@Override
public void onResult( final AIResponse response) {
Log.i("", response.toString());
ArrayList<String> ap = new ArrayList<>();
ArrayList<String> apk = new ArrayList<>();
final Result result1 = response.getResult();
String parameterString = "";
if (result1.getParameters() != null &&
!result1.getParameters().isEmpty()) {
for (final Map.Entry<String, JsonElement> entry :
result1.getParameters().entrySet()) {
parameterString += "(" + entry.getKey() + ", " +
entry.getValue() + ") ";
}
}
final String sppech = result1.getFulfillment().getSpeech();
String ae = result1.getResolvedQuery().toString();
a.setText("\n Baymax: " + result1.getFulfillment().getSpeech());
resp.setText("\n You: " + result1.getResolvedQuery());
// Show results in TextView.
joi.speak(result1.getFulfillment().getSpeech(),
TextToSpeech.QUEUE_FLUSH, null, null);
}
@Override
public void onError(AIError error)
{
resp.setText(error.toString());
}
@Override
public void onAudioLevel(float level) {
}
@Override
public void onListeningStarted() {
}
@Override
public void onListeningCanceled() {
}
@Override
public void onListeningFinished() {
}
}
[Скриншот приложения] [1]
[Скриншот Intent, Entity & Test Console] [1]
[1]: https://imgur.com/a/Qs0CWhK "App Screenshot"
[2]: https://imgur.com/a/v3dz2tI "Intent, Entity & Test Console Screenshot"