เราจะเลิกใช้งานการดําเนินการสนทนาในวันที่ 13 มิถุนายน 2023 โปรดดูข้อมูลเพิ่มเติมในการสิ้นสุดการดําเนินการสนทนา

คําตอบทั่วไป (Dialogflow)

จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ

สํารวจใน Dialogflow

คลิกต่อไปเพื่อนําเข้าตัวอย่างการตอบกลับใน Dialogflow จากนั้นทําตามขั้นตอนด้านล่างเพื่อทําให้ใช้งานได้และทดสอบตัวอย่าง

  1. ป้อนชื่อตัวแทนแล้วสร้าง Agent ใหม่ใน Dialogflow สําหรับตัวอย่าง
  2. หลังจากตัวแทนนําเข้าเสร็จแล้ว ให้คลิกไปที่ตัวแทน
  3. จากเมนูการนําทางหลัก ให้ไปที่การดําเนินการ
  4. เปิดใช้เครื่องมือแก้ไขในบรรทัด แล้วคลิกทําให้ใช้งานได้ ตัวแก้ไขมีโค้ดตัวอย่างอยู่
  5. จากเมนูการนําทางหลัก ให้ไปที่การผสานรวม แล้วคลิก Google Assistant
  6. ในหน้าต่างโมดัลที่ปรากฏขึ้น ให้เปิดใช้แสดงตัวอย่างการเปลี่ยนแปลงอัตโนมัติ แล้วคลิกทดสอบเพื่อเปิดเครื่องจําลองการดําเนินการ
  7. ในเครื่องจําลอง ให้ป้อน Talk to my test app เพื่อทดสอบตัวอย่าง

คําตอบง่ายๆ จะอยู่ในรูปแบบลูกโป่งแชทและใช้การอ่านออกเสียงข้อความ (TTS) หรือภาษามาร์กอัปสังเคราะห์เสียง (SSML) กับเสียง

ข้อความ TTS จะใช้เป็นเนื้อหาลูกโป่งแชทโดยค่าเริ่มต้น หากแง่มุมของข้อความนั้นตรงกับความต้องการของคุณ คุณไม่จําเป็นต้องระบุข้อความการแสดงผลสําหรับลูกโป่งแชท

และอ่านหลักเกณฑ์การออกแบบการสนทนาเพื่อดูวิธีรวมองค์ประกอบภาพเหล่านี้ไว้ในการดําเนินการของคุณ

พร็อพเพอร์ตี้

รูปที่ 1 ตัวอย่างการตอบกลับอย่างง่าย (สมาร์ทโฟน)

การตอบกลับแบบง่ายมีข้อกําหนดและพร็อพเพอร์ตี้ที่ไม่บังคับต่อไปนี้ซึ่งคุณกําหนดค่าได้

  • รองรับในแพลตฟอร์มที่มีความสามารถ actions.capability.AUDIO_OUTPUT หรือ actions.capability.SCREEN_OUTPUT
  • จํานวนอักขระในแชทสูงสุด 640 อักขระ สตริงที่ยาวกว่าขีดจํากัดจะถูกตัดออกที่ตัวแบ่งคําแรก (หรือช่องว่าง) ก่อนอักขระ 640 ตัว

  • เนื้อหาลูกโป่งแชทต้องเป็นชุดย่อยของการออกเสียงหรือข้อความถอดเสียงของเอาต์พุต TTS/SSML ที่สมบูรณ์ ซึ่งจะช่วยให้ผู้ใช้อธิบายสิ่งที่คุณพูดและเพิ่มความเข้าใจในเงื่อนไขต่างๆ ได้

  • บับเบิลแชทสูงสุด 2 รายการต่อครั้ง

  • ส่วนหัวแชท (โลโก้) ที่คุณส่งไปยัง Google ต้องมีขนาด 192x192 พิกเซล และต้องไม่เป็นภาพเคลื่อนไหว

รูปที่ 2 ตัวอย่างคําตอบแบบง่าย (Smart Display)

รหัสตัวอย่าง

Node.js

app.intent('Simple Response', (conv) => {
  conv.ask(new SimpleResponse({
    speech: `Here's an example of a simple response. ` +
      `Which type of response would you like to see next?`,
    text: `Here's a simple response. ` +
      `Which response would you like to see next?`,
  }));
});

Java

@ForIntent("Simple Response")
public ActionResponse welcome(ActionRequest request) {
  ResponseBuilder responseBuilder = getResponseBuilder(request);
  responseBuilder.add(
      new SimpleResponse()
          .setTextToSpeech(
              "Here's an example of a simple response. "
                  + "Which type of response would you like to see next?")
          .setDisplayText(
              "Here's a simple response. Which response would you like to see next?"));
  return responseBuilder.build();
}

Node.js

conv.ask(new SimpleResponse({
  speech: `Here's an example of a simple response. ` +
    `Which type of response would you like to see next?`,
  text: `Here's a simple response. ` +
    `Which response would you like to see next?`,
}));

Java

ResponseBuilder responseBuilder = getResponseBuilder(request);
responseBuilder.add(
    new SimpleResponse()
        .setTextToSpeech(
            "Here's an example of a simple response. "
                + "Which type of response would you like to see next?")
        .setDisplayText(
            "Here's a simple response. Which response would you like to see next?"));
return responseBuilder.build();

JSON

โปรดทราบว่า JSON ด้านล่างอธิบายการตอบสนองของเว็บฮุค

{
  "payload": {
    "google": {
      "expectUserResponse": true,
      "richResponse": {
        "items": [
          {
            "simpleResponse": {
              "textToSpeech": "Here's an example of a simple response. Which type of response would you like to see next?",
              "displayText": "Here's a simple response. Which response would you like to see next?"
            }
          }
        ]
      }
    }
  }
}

JSON

โปรดทราบว่า JSON ด้านล่างอธิบายการตอบสนองของเว็บฮุค

{
  "expectUserResponse": true,
  "expectedInputs": [
    {
      "possibleIntents": [
        {
          "intent": "actions.intent.TEXT"
        }
      ],
      "inputPrompt": {
        "richInitialPrompt": {
          "items": [
            {
              "simpleResponse": {
                "textToSpeech": "Here's an example of a simple response. Which type of response would you like to see next?",
                "displayText": "Here's a simple response. Which response would you like to see next?"
              }
            }
          ]
        }
      }
    }
  ]
}

SSML และเสียง

การใช้ SSML และเสียงในคําตอบของคุณจะช่วยปรับคุณภาพแอปให้ดีขึ้นและยกระดับประสบการณ์ของผู้ใช้ ข้อมูลโค้ดต่อไปนี้จะแสดงวิธีสร้างการตอบกลับที่ใช้ SSML

Node.js

app.intent('SSML', (conv) => {
  conv.ask(`<speak>` +
    `Here are <say-as interpet-as="characters">SSML</say-as> examples.` +
    `Here is a buzzing fly ` +
    `<audio src="https://actions.google.com/sounds/v1/animals/buzzing_fly.ogg"></audio>` +
    `and here's a short pause <break time="800ms"/>` +
    `</speak>`);
  conv.ask('Which response would you like to see next?');
});

Java

@ForIntent("SSML")
public ActionResponse ssml(ActionRequest request) {
  ResponseBuilder responseBuilder = getResponseBuilder(request);
  responseBuilder.add(
      "<speak>"
          + "Here are <say-as interpet-as=\"characters\">SSML</say-as> examples."
          + "Here is a buzzing fly "
          + "<audio src=\"https://actions.google.com/sounds/v1/animals/buzzing_fly.ogg\"></audio>"
          + "and here's a short pause <break time=\"800ms\"/>"
          + "</speak>");
  return responseBuilder.build();
}

Node.js

conv.ask(`<speak>` +
  `Here are <say-as interpet-as="characters">SSML</say-as> examples.` +
  `Here is a buzzing fly ` +
  `<audio src="https://actions.google.com/sounds/v1/animals/buzzing_fly.ogg"></audio>` +
  `and here's a short pause <break time="800ms"/>` +
  `</speak>`);
conv.ask('Which response would you like to see next?');

Java

ResponseBuilder responseBuilder = getResponseBuilder(request);
responseBuilder.add(
    "<speak>"
        + "Here are <say-as interpet-as=\"characters\">SSML</say-as> examples."
        + "Here is a buzzing fly "
        + "<audio src=\"https://actions.google.com/sounds/v1/animals/buzzing_fly.ogg\"></audio>"
        + "and here's a short pause <break time=\"800ms\"/>"
        + "</speak>");
return responseBuilder.build();

JSON

โปรดทราบว่า JSON ด้านล่างอธิบายการตอบสนองของเว็บฮุค

{
  "payload": {
    "google": {
      "expectUserResponse": true,
      "richResponse": {
        "items": [
          {
            "simpleResponse": {
              "textToSpeech": "<speak>Here are <say-as interpet-as=\"characters\">SSML</say-as> examples.Here is a buzzing fly <audio src=\"https://actions.google.com/sounds/v1/animals/buzzing_fly.ogg\"></audio>and here's a short pause <break time=\"800ms\"/></speak>"
            }
          },
          {
            "simpleResponse": {
              "textToSpeech": "Which response would you like to see next?"
            }
          }
        ]
      }
    }
  }
}

JSON

โปรดทราบว่า JSON ด้านล่างอธิบายการตอบสนองของเว็บฮุค

{
  "expectUserResponse": true,
  "expectedInputs": [
    {
      "possibleIntents": [
        {
          "intent": "actions.intent.TEXT"
        }
      ],
      "inputPrompt": {
        "richInitialPrompt": {
          "items": [
            {
              "simpleResponse": {
                "textToSpeech": "<speak>Here are <say-as interpet-as=\"characters\">SSML</say-as> examples.Here is a buzzing fly <audio src=\"https://actions.google.com/sounds/v1/animals/buzzing_fly.ogg\"></audio>and here's a short pause <break time=\"800ms\"/></speak>"
              }
            },
            {
              "simpleResponse": {
                "textToSpeech": "Which response would you like to see next?"
              }
            }
          ]
        }
      }
    }
  ]
}

โปรดดูข้อมูลเพิ่มเติมที่เอกสารอ้างอิง SSML

คลังเพลงและเสียง

เรามีเสียงสั้นๆ ที่ใช้งานได้ฟรีในคลังเพลงและเสียง เสียงเหล่านี้โฮสต์ให้คุณแล้ว สิ่งที่ต้องทําคือใส่เสียงใน SSML