关于.netframework4 下语音识别Form程序中播放MP3的问题: 谢谢各位了! 30
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Da...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.Runtime.InteropServices;
using System.Media;
using System.Threading;
public Form1()
{
InitializeComponent();
myPtr = GetForegroundWindow();
SRE.SetInputToDefaultAudioDevice(); // <=======默认的语音输入设备,你可以设定为去识别一个WAV文件。
GrammarBuilder GB = new GrammarBuilder();
//GB.Append("选择");
GB.Append(new Choices(new string[] { "红色", "绿色","开始" }));
Grammar G = new Grammar(GB);
G.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(G_SpeechRecognized);
SRE.LoadGrammar(G);
SRE.RecognizeAsync(RecognizeMode.Multiple); //<=======异步调用识别引擎,允许多次识别(否则程序只响应你的一句话)
}
void G_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) {
//Text = e.Result.Text;
//MessageBox.Show(e.Result.Text);
switch (e.Result.Text) {
case "红色":
BackColor = Color.Red;
break;
case "绿色":
BackColor = Color.Green; //窗口颜色变为红色
break;
case "开始":
new Play().plays();//启动音乐播放(但是音乐不能播放出来!)求解答
break;
}
}
class Play {
[DllImport("winmm.dll")]
public static extern uint mciSendString(string lpstrCommand,
string lpstrReturnString, uint uReturnLength, uint hWndCallback);
public void plays() {
//MessageBox.Show("fsdfsdffds");
//System.Diagnostics.Process.Start(@"F:\Program Files\Tencent\QQ\Bin\QQ.exe");
mciSendString(@"close temp_alias", null, 0, 0);
mciSendString(@"open D:\KwDownload\song\林俊杰-她说.wma alias temp_alias", null, 0, 0);
mciSendString("play temp_alias repeat", null, 0, 0);
//MessageBox.Show("fsdfsdffds");
}
} 展开
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.Runtime.InteropServices;
using System.Media;
using System.Threading;
public Form1()
{
InitializeComponent();
myPtr = GetForegroundWindow();
SRE.SetInputToDefaultAudioDevice(); // <=======默认的语音输入设备,你可以设定为去识别一个WAV文件。
GrammarBuilder GB = new GrammarBuilder();
//GB.Append("选择");
GB.Append(new Choices(new string[] { "红色", "绿色","开始" }));
Grammar G = new Grammar(GB);
G.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(G_SpeechRecognized);
SRE.LoadGrammar(G);
SRE.RecognizeAsync(RecognizeMode.Multiple); //<=======异步调用识别引擎,允许多次识别(否则程序只响应你的一句话)
}
void G_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) {
//Text = e.Result.Text;
//MessageBox.Show(e.Result.Text);
switch (e.Result.Text) {
case "红色":
BackColor = Color.Red;
break;
case "绿色":
BackColor = Color.Green; //窗口颜色变为红色
break;
case "开始":
new Play().plays();//启动音乐播放(但是音乐不能播放出来!)求解答
break;
}
}
class Play {
[DllImport("winmm.dll")]
public static extern uint mciSendString(string lpstrCommand,
string lpstrReturnString, uint uReturnLength, uint hWndCallback);
public void plays() {
//MessageBox.Show("fsdfsdffds");
//System.Diagnostics.Process.Start(@"F:\Program Files\Tencent\QQ\Bin\QQ.exe");
mciSendString(@"close temp_alias", null, 0, 0);
mciSendString(@"open D:\KwDownload\song\林俊杰-她说.wma alias temp_alias", null, 0, 0);
mciSendString("play temp_alias repeat", null, 0, 0);
//MessageBox.Show("fsdfsdffds");
}
} 展开
1个回答
2011-02-01
展开全部
你应该是调用QQmusic.exe吧??
怎么调用QQ了???
怎么调用QQ了???
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询