編集履歴一覧に戻る
fukumuraのアイコン画像

fukumura が 2021年05月16日20時20分41秒 に編集

コメント無し

本文の変更

Google Nest HubやLINE CLOVA DWSKだと話した内容がモニターにリアルタイムに表示してくれますが、Echo Showでは表示してくれません。 そのため、obnizを使って話した内容を表示させてみました。

-

https://youtu.be/fZ7TZTnGras

+

<iframe width="644" height="362" src="https://www.youtube.com/embed/fZ7TZTnGras" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

Alexaのカスタムスキルをhostedスキルで実装します。 ```Alexa:Alexa側 const Alexa = require('ask-sdk-core'); const webclient = require('request'); const LaunchRequestHandler = { canHandle(handlerInput) { return Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest'; }, handle(handlerInput) { const speakOutput = 'オブナイズテキスト表示にようこそ'; return handlerInput.responseBuilder .speak(speakOutput) .reprompt(speakOutput) .getResponse(); } }; const HelloWorldIntentHandler = { canHandle(handlerInput) { return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' && Alexa.getIntentName(handlerInput.requestEnvelope) === 'HelloWorldIntent'; }, handle(handlerInput) { const speakOutput = handlerInput.requestEnvelope.request.intent.slots.message.value; // obniz呼び出し const obnizUrl = '<obnizのWebhook URL(GET/POST)>'; webclient.get({ url: obnizUrl, qs: { message: speakOutput } }, function (error, response, body) { console.log(body); }); return handlerInput.responseBuilder .speak(speakOutput) .reprompt(speakOutput) .getResponse(); } }; exports.handler = Alexa.SkillBuilders.custom() .addRequestHandlers( LaunchRequestHandler, HelloWorldIntentHandler, HelpIntentHandler, CancelAndStopIntentHandler, FallbackIntentHandler, SessionEndedRequestHandler, IntentReflectorHandler) .addErrorHandlers( ErrorHandler) .withCustomUserAgent('sample/hello-world/v1.2') .lambda(); ``` obnizはアプリとして実装します。 ```obniz:obniz側 <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" /> <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script> <script src="https://unpkg.com/obniz@3.x/obniz.js" crossorigin="anonymous" ></script> </head> <body> <div id="obniz-debug"></div> <script> const obniz = new Obniz("OBNIZ_ID_HERE"); // called on online obniz.onconnect = async function() { let request = {}; if (typeof req === "object") { request = req; obniz.display.clear(); obniz.display.print(request.query.message); Obniz.App.done(); } // called while online. obniz.onloop = async function() { }; }; // called on offline obniz.onclose = async function() { }; </script> </body> </html> ``` アプリの設定で「Webhookで実行」をONにします。 ![キャプションを入力できます](https://camo.elchika.com/39e38960ebdfcbfe69ac0a0fea0c9b64d6a10511/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f34663930313133612d303037382d343564332d396561392d3833336633646530353538362f65313634656263362d306137332d343162392d613536662d313661366437303938356566/) デバイス画面で「Webhook URLの確認」をクリックします。 ![キャプションを入力できます](https://camo.elchika.com/034184d24f3ac6f40d7b7a8728b5b628f1e8ec3f/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f34663930313133612d303037382d343564332d396561392d3833336633646530353538362f35363035646337302d626139662d343166642d383236612d303236663035653663323634/) 「Webhook URL(GET/POST)」の値をAlexa側のコードに設定します。 ![キャプションを入力できます](https://camo.elchika.com/ac8ec0992cc16961588d4dcd36c229bc1cd50f48/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f34663930313133612d303037382d343564332d396561392d3833336633646530353538362f37376134383866352d393035622d343337652d623865312d383963336262633836613030/) これでAlexaでスキルを起動して、その後、発話した内容がobnizに表示されます。