音声入力の問題を管理する方法 (HTML)
[ この記事は、Windows ランタイム アプリを作成する Windows 8.x および Windows Phone 8.x 開発者を対象としています。Windows 10 向けの開発を行っている場合は、「最新のドキュメント」をご覧ください]
オーディオ入力の品質と条件が原因で発生する音声認識の精度の問題を管理する方法について説明します。
理解しておく必要があること
テクノロジ
必要条件
このトピックは、「クイック スタート: 音声認識」に基づいています。
このチュートリアルを完了するには、以下のトピックに目を通して、ここで説明されているテクノロジをよく理解できるようにしてください。
- Microsoft Visual Studio をインストールします。
- 開発者用ライセンスを取得します。詳しくは、「Visual Studio 2013 を使った開発」をご覧ください。
- JavaScript を使って初めての Windows ストア アプリを作成します。
- JavaScript を使った Windows ストア アプリのためのロードマップ
- イベントについては、「クイック スタート: HTML コントロールの追加とイベントの処理」をご覧ください。
- 「音声機能の設計ガイドライン」にある、魅力的な音声認識対応アプリの設計に役立つ便利なヒントをご覧ください。
手順
ステップ 1: オーディオ入力の品質を評価する
音声認識がアクティブな場合は、音声認識エンジンの RecognitionQualityDegrading イベントを使用して、1 つ以上のオーディオの問題によって音声入力が妨げられている可能性があるかどうかを判断します。 イベント引数 (SpeechRecognitionQualityDegradingEventArgs) には、problem プロパティがあり、音声入力で検出された問題の説明が含まれています。
認識は、多すぎる背景の雑音、ミュートされたマイク、およびスピーカーのボリュームや速度の影響を受ける場合があります。
ここでは、音声認識エンジンを構成し、recognitionqualitydegrading イベントのリッスンを開始します。
function buttonSpeechRecognizerQualityDegradingClick() {
// Create an instance of a speech recognizer.
var speechRecognizer =
new Windows.Media.SpeechRecognition.SpeechRecognizer();
// Listen for audio input issues.
speechRecognizer.addEventListener(
"recognitionqualitydegrading",
onRecognitionQualityDegrading,
false);
// Compile the default dictation grammar.
speechRecognizer.compileConstraintsAsync().then(
// Success function.
function (result) {
// Start recognition.
speechRecognizer.recognizeWithUIAsync().done();
},
// Error function.
function (err) {
WinJS.log && WinJS.log("Constraint compilation failed.");
});
speechRecognizer.close();
}
ステップ 2: 音声認識エクスペリエンスを管理する
problem プロパティにある説明を使用して、ユーザーが認識の状態を改善できるようにします。
ここでは、低い音量レベルをチェックする recognitionqualitydegrading イベント用のハンドラーを作成します。次に、SpeechSynthesizer オブジェクト使って、より大きな声で話すことをユーザーに提示します。
function onRecognitionQualityDegrading(args) {
// Create an instance of a speech synthesis engine (voice).
var speechSynthesizer =
new Windows.Media.SpeechSynthesis.SpeechSynthesizer();
// Create an object for controlling and playing an audio stream.
var audio = new Audio();
// If input speech is too quiet, prompt the user to speak louder.
if (args.problem === Windows.Media.SpeechRecognition.SpeechRecognitionAudioProblem.tooQuiet) {
// Generate the audio stream from plain text.
speechSynthesizer.synthesizeTextToStreamAsync("Try speaking louder").done(
// Success function.
function (markersStream) {
// Convert the stream to a URL Blob.
var blob = MSApp.createBlobFromRandomAccessStream(markersStream.ContentType, markersStream);
// Send the Blob to the audio object.
audio.src = URL.createObjectURL(blob, { oneTimeOnly: true });
// Start at beginning.
markersStream.seek(0);
audio.play();
},
// Error function.
function (err) {
WinJS.log && WinJS.log("Speech synthesis failed.");
});
}
speechSynthesizer.close();
}
関連トピック
デザイナー向け