音声コマンド定義 (VCD) の語句一覧を動的に変更する方法 (HTML)

[ この記事は、Windows ランタイム アプリを作成する Windows 8.x および Windows Phone 8.x 開発者を対象としています。Windows 10 向けの開発を行っている場合は、「最新のドキュメント」をご覧ください]

実行時に音声認識結果を使って、VCD ファイルのサポート対象語句の一覧 (PhraseList 要素) にアクセスして更新する方法を説明します。

実行時に動的に語句一覧を変更できると、ある種のユーザー定義のお気に入りデータや一時的なアプリ データが関係する作業専用の音声コマンドを使う場合に便利です。

たとえば、ユーザーが目的地を入力できる旅行アプリがあり、ユーザーがアプリ名の後に「"<目的地> 旅行を表示"」と発声するだけでアプリを起動できるようにするとします。想定されるすべての目的地について個別の ListenFor 要素を作成する必要はありません。代わりに、ユーザーが作った目的地を実行時に動的に PhraseList に設定できます。ListenFor 要素自体では、<ListenFor> Show trip to {destination} </ListenFor> のように指定できます。ここで、"destination" は、PhraseListLabel 属性の値です。

PhraseList などの VCD 要素について詳しくは、「VCD elements and attributes v1.2」をご覧ください。

必要条件

このトピックは、「クイック スタート: Cortana の音声コマンド」に基づいています。ここでは、引き続き Adventure Works という旅行の計画および管理アプリを使って機能について説明します。

このチュートリアルを完了するには、以下のトピックに目を通して、ここで説明されているテクノロジをよく理解できるようにしてください。

手順

ステップ 1: コマンドの特定

VCD ファイルの PhraseList 要素を更新するには、語句一覧を含む CommandSet 要素を取得します。CommandSet 要素の Name 属性 (Name は VCD ファイル内で重複しないようにします) をキーとして VoiceCommandManager.installedCommandSets プロパティにアクセスし、voiceCommandSet の参照を取得します。

ステップ 2: 語句一覧の置換

コマンド セットを特定したら、変更する語句一覧の参照を取得し、PhraseList 要素の Label 属性と文字列の配列を、語句一覧の新しい内容として setPhraseListAsync を呼び出します。

  語句一覧は、変更すると語句一覧全体が置き換えられます。語句一覧に新しい項目を追加する場合は、既にある項目と新しい項目の両方を指定して setPhraseListAsync を呼び出す必要があります。

 

ここでは、VCD ファイルは Command"showTripToDestination" と、Adventure Works 旅行アプリで目的地を選ぶための 3 つのオプションを定義する PhraseList を定義します。ユーザーがアプリで目的地を保存および削除すると、アプリは PhraseList のオプションを更新します。

<?xml version="1.0" encoding="utf-8"?>
<VoiceCommands xmlns="https://schemas.microsoft.com/voicecommands/1.1">
  <CommandSet xml:lang="en-us" Name="AdventureWorksCommandSet_en-us">
    <CommandPrefix> Adventure Works, </CommandPrefix>
    <Example> Show trip to London </Example>

    <Command Name="showTripToDestination">
      <Example> show trip to London  </Example>
      <ListenFor> show trip to {destination} </ListenFor>
      <Feedback> Showing trip to {destination} </Feedback>
      <Navigate/>
    </Command>

    <PhraseList Label="destination">
      <Item> London </Item>
      <Item> Dallas </Item>
      <Item> New York </Item>
    </PhraseList>

  </CommandSet>

<!-- Other CommandSets for other languages -->

</VoiceCommands>

次に、この例の PhraseList を更新して、目的地「フェニックス」を追加する方法を示します。

N/A

注釈

PhraseList を使った認識の制約は、比較的少ないセットや単語に適しています。単語セットが大きすぎ (数百語など) たり、まったく制約しない場合は、PhraseTopic 要素と Subject 要素を使って音声認識結果の関連性を絞り込み、スケーラビリティを高めます。

この例では、Scenario が「"Search"」の PhraseTopic があり、「"City\State"」という Subject によってさらに絞り込まれています。

<?xml version="1.0" encoding="utf-8"?>
<VoiceCommands xmlns="https://schemas.microsoft.com/voicecommands/1.1">
  <CommandSet xml:lang="en-us" Name="AdventureWorksCommandSet_en-us">
    <CommandPrefix> Adventure Works, </CommandPrefix>
    <Example> Show trip to London </Example>

    <Command Name="showTripToDestination">
      <Example> show trip to London  </Example>
      <ListenFor> show trip to {destination} </ListenFor>
      <Feedback> Showing trip to {destination} </Feedback>
      <Navigate/>
    </Command>

    <PhraseList Label="destination">
      <Item> London </Item>
      <Item> Dallas </Item>
      <Item> New York </Item>
    </PhraseList>

    <PhraseTopic Label="destination" Scenario="Search">
      <Subject>City/State</Subject>
    </PhraseTopic>

  </CommandSet>

関連トピック

Cortana の操作

Cortana の音声コマンドを使ったフォアグラウンド アプリの起動

Cortana の音声コマンドを使ったバックグラウンド アプリの起動

VCD elements and attributes v1.2

デザイナー向け

Cortana の設計ガイドライン