###前提・実現したいこと
現在、音声認識を利用したディスクトップアプリケーションを作成しています。
どのようなものかといいますと声でiPhoneを操作できる「Siri」のようにディスクトップ上でも声を使い、アプリを立ち上げる(終了させる)操作が出来るというものです。
いろいろ調べながら基礎的なプログラムは完成したのですがUIの作成に手間取ってしまい皆様のお力を貸してもらいたいです。
操作手順としては、
1.起動したいアプリを指定のBOXにD&D
2.そのアプリを起動するための起動ワード・終了ワードを打ち込み登録ボタンを押す
3.登録されたアプリの情報は、リストに登録されユーザーが任意に登録した起動ワードやパスを変更、又は削除できる。
以上のようなものを目指して調べながら作成していたのですがうまくいかず作成が止まってしまっています。
作成例、またはヒントを教えてほしいです。
よろしくお願いします。
下の画像は完成イメージ図になります。
イメージ図に記載し忘れていますが起動・終了するための言葉を入力するBOXと誤って別のアプリをD&Dしてしまったものを「取り消す」ボタンも作成したいと思っています。
以下作成したプログラミンです。
「grammar.xml」が辞書ファイルになります。
###Form1.cs
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Speech.Recognition; using System.Xml; using System.Diagnostics; using System.Speech; namespace xxx { public partial class Form1 : Form { public Form1() { InitializeComponent(); { SpeechRecognitionEngine engine = new SpeechRecognitionEngine(); engine.SpeechRecognized += delegate(object sender, SpeechRecognizedEventArgs e) { int hour = DateTime.Now.Hour; //現在時刻(hour)を答える string min = DateTime.Now.Minute.ToString("d"); //現在時刻(min)を答える { if (e.Result.Confidence > 0.4f) //音声の聞き取り精度(0.1~1.0f) switch (e.Result.Text) { //時間 case "今何時"://ここに命令 if (hour < 13) { //am System.Diagnostics.Process.Start(@"C:\Users\xxx\Desktop\sozai\toki\hour\am.wav"); System.Threading.Thread.Sleep(1000); System.Diagnostics.Process.Start(@"C:\Users\xxx\Desktop\sozai\toki\hour\" + hour + ".wav"); System.Threading.Thread.Sleep(500); System.Diagnostics.Process.Start(@"C:\Users\xxx\Desktop\sozai\toki\hour\時.wav"); System.Threading.Thread.Sleep(1000); System.Diagnostics.Process.Start(@"C:\Users\xxx\Desktop\sozai\toki\min\" + min + ".wav"); System.Threading.Thread.Sleep(1200); System.Diagnostics.Process.Start(@"C:\Users\xxx\Desktop\sozai\toki\min\分.wav"); } else { //pm System.Diagnostics.Process.Start(@"C:\Users\xxx\Desktop\sozai\toki\hour\" + hour + ".wav"); System.Threading.Thread.Sleep(1000); System.Diagnostics.Process.Start(@"C:\Users\xxx\Desktop\sozai\toki\hour\" + hour + ".wav"); System.Threading.Thread.Sleep(500); System.Diagnostics.Process.Start(@"C:\Users\xxx\Desktop\sozai\toki\hour\時.wav"); System.Threading.Thread.Sleep(1000); System.Diagnostics.Process.Start(@"C:\Users\xxx\Desktop\sozai\toki\min\" + min + ".wav"); System.Threading.Thread.Sleep(1200); System.Diagnostics.Process.Start(@"C:\Users\xxx\Desktop\sozai\toki\min\分.wav"); } break; case "ワード"://ここに命令 System.Diagnostics.Process.Start(@"C:\xxx..."); break; case "エクセル"://ここに命令 System.Diagnostics.Process.Start(@"C:\xxx..."); break; case "パワポ"://ここに命令 case "パワーポイント": System.Diagnostics.Process.Start(@"C:\xxx..."); break; case "〇〇終了"://ここに命令 case "〇〇閉じる": System.Diagnostics.Process.Start(@"C:\xxx..."); Application.Exit(); //このアプリを終了する break; } } }; Grammar g = new Grammar(@"C:\Users\xxx\Documents\Visual Studio 2015\Projects\xxx\grammar.xml", "command"); engine.LoadGrammar(g); engine.LoadGrammar(new DictationGrammar()); engine.SetInputToDefaultAudioDevice(); engine.RecognizeAsync(RecognizeMode.Multiple); } } } }
###grammar.xml
<?xml version="1.0" encoding="UTF-8"?> <grammar xml:lang="ja-JP" root="command" tag-format="semantics/1.0" xmlns="http://www.w3.org/2001/06/grammar" version="1.0"> <rule scope="public" id="command"> <one-of> <item>ワード</item> <item>エクセル</item> <item>パワポ</item> <item>パワーポイント</item> <item>〇〇終了</item> <item>〇〇閉じる</item> </one-of> </rule> </grammar>
###補足情報(言語/FW/ツール等のバージョンなど)
開発環境:visualstudio2015
開発言語:C#
OS:Windows8.1
回答1件
あなたの回答
tips
プレビュー