日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當前位置:首頁 > 單片機 > 單片機
[導讀]第六章:利用Kinect語音識別控制51單片機WPF部分:(1) 新建 Visual C# --> WPF工程(如下圖),記得右鍵點擊“引用”,添加相應驅動版本的Microsoft.Kinect.dll 和Microsoft.Speech動態(tài)庫。App.xaml 文件及 App.xaml

第六章:利用Kinect語音識別控制51單片機


WPF部分:


(1) 新建 Visual C# --> WPF工程(如下圖),記得右鍵點擊“引用”,添加相應驅動版本的Microsoft.Kinect.dll 和Microsoft.Speech動態(tài)庫。App.xaml 文件及 App.xaml.cs文件無需改動。




(2)下面是MainWindow.xaml.cs文件的內(nèi)容。


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Navigation;

using System.Windows.Shapes;


using Microsoft.Kinect;

using Microsoft.Speech.AudioFormat;

using Microsoft.Speech.Recognition;


using System.IO;


using System.IO.Ports; //跟串口相關,不能只是引用system.IO

using System.Threading; //跟串口相關,線程的引入


namespace VoiceControlLED

{

///

/// Interaction logic for MainWindow.xaml

///

public partial class MainWindow : Window

{


KinectSensor myKinect;

///

/// 音控相關

///

RecognizerInfo kinectRecognizerInfo;

SpeechRecognitionEngine recognizer;

KinectAudioSource kinectSource;

Stream audioStream;


///

/// 串口相關

///

///

delegate void HandleInterfaceUpdateDelagate(string text);//委托;此為重點

///

/// 實例化串口

///

SerialPort serialPort1 = new SerialPort();

///

/// 串口初始化函數(shù)

///

private void SerialPort1_Init()

{

serialPort1.PortName = "COM1"; //串口號(參考串口調試助手)

serialPort1.BaudRate = 9600; //波特率

serialPort1.Parity = Parity.None; //校驗位

serialPort1.DataBits = 8; //數(shù)據(jù)位

serialPort1.StopBits = StopBits.One; //停止位


if (!serialPort1.IsOpen)

{

serialPort1.Open();

}

else

MessageBox.Show("Port is open!");

}


///

/// 發(fā)送字節(jié)數(shù)據(jù)函數(shù)

///

///

///

private int send_command(string Command)

{

try

{

serialPort1.Write(Command);

return (1);

}

catch (Exception)

{

// comm error

return (0);

}

}


private RecognizerInfo findKinectRecognizerInfo()

{

var recognizers = SpeechRecognitionEngine.InstalledRecognizers();


foreach (RecognizerInfo recInfo in recognizers)

{

// look at each recognizer info value to find the one that works for Kinect

if (recInfo.AdditionalInfo.ContainsKey("Kinect"))

{

string details = recInfo.AdditionalInfo["Kinect"];

if (details == "True" && recInfo.Culture.Name == "en-US")

{

// If we get here we have found the info we want to use

return recInfo;

}

}

}

return null;

}


private void createSpeechEngine()

{

kinectRecognizerInfo = findKinectRecognizerInfo();


if (kinectRecognizerInfo == null)

{

MessageBox.Show("Kinect recognizer not found", "Kinect Speech Demo");

Application.Current.Shutdown();

return;

}


try

{

recognizer = new SpeechRecognitionEngine(kinectRecognizerInfo);

}

catch

{

MessageBox.Show("Speech recognition engine could not be loaded", "Kinect Speech Demo");

Application.Current.Shutdown();

}

}


private void buildCommands()

{

Choices commands = new Choices();


commands.Add("One");

commands.Add("Two");

commands.Add("Three");

commands.Add("Four");

commands.Add("Five");

commands.Add("Six");

commands.Add("Seven");

commands.Add("Eight");


GrammarBuilder grammarBuilder = new GrammarBuilder();


grammarBuilder.Culture = kinectRecognizerInfo.Culture;

grammarBuilder.Append(commands);


Grammar grammar = new Grammar(grammarBuilder);


recognizer.LoadGrammar(grammar);

}


private void setupAudio()

{

try

{

myKinect = KinectSensor.KinectSensors[0];

myKinect.Start();

kinectSource = myKinect.AudioSource;

kinectSource.BeamAngleMode = BeamAngleMode.Automatic;

audioStream = kinectSource.Start();

recognizer.SetInputToAudioStream(audioStream, new SpeechAudioFormatInfo(

EncodingFormat.Pcm, 16000, 16, 1,

32000, 2, null));

recognizer.RecognizeAsync(RecognizeMode.Multiple);

}

catch

{

MessageBox.Show("Audio stream could not be connected", "Kinect Speech Demo");

Application.Current.Shutdown();

}

}



private void SetupSpeechRecognition()

{

本站聲明: 本文章由作者或相關機構授權發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權益,請及時聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關閉