大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
成都创新互联公司是网站建设技术企业,为成都企业提供专业的成都网站建设、做网站,网站设计,网站制作,网站改版等技术服务。拥有10余年丰富建站经验和众多成功案例,为您定制适合企业的网站。10余年品质,值得信赖!
For Each FileName As String In IO.Directory.GetFiles("E:\音乐", "*.mp3")
TextBox1.Text = vbNewLine IO.Path.GetFileName(FileName)
Next
End Sub
A simple Sound Recorder~
1. Add Three buttons (button1, button2, button3) and a label (label1) to the form.
2. Set the Text of Button1 to Start, Button2 to Stop, and Button3 to Play.
3. Add this code:
Public Class Form1
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Button1.Enabled = False
Button2.Enabled = True
mciSendString("open new Type waveaudio Alias recsound", "", 0, 0)
mciSendString("record recsound", "", 0, 0)
Label1.Text = "Recording..."
Label1.Visible = True
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Button1.Enabled = True
Button2.Enabled = False
Button3.Enabled = True
mciSendString("save recsound c:\recsound.wav", "", 0, 0)
mciSendString("close recsound", "", 0, 0)
MsgBox("File Created: C:\recsound.wav")
Label1.Text = "Stopped..."
Label1.Visible = False
My.Computer.Audio.Stop()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Label1.Text = "Playing..."
Label1.Visible = True
My.Computer.Audio.Play("c:\recsound.wav", AudioPlayMode.Background)
End Sub
End Class
首先添加一个系统的语音COM组件的引用microsoft speech object library然后在程序中声明一个语音类dim RC As SpeechLib.SpSharedRecoContext这个类有一些事件,如果你要处理它的一些事件,可以用withevent来声明然后在窗体LOAD事件或你需要的地方先创建一个实例RC = New SpeechLib.SpSharedRecoContext当一个RC被实例化后,系统就会运行语音识别程序.前提是你的系统已经正确安装这个功能.一般默认就已经安装好的.其次提醒一下,WIN7的语音识别比XP的好N倍.从阅读到侦听都好很多.然后就可以在你需要阅读的地方使用RC.Voice.Speak("hello 我", 11)11那里是一些枚举,用来标识系统用前台还是后台或其他方式来阅读文字,简单的来说就是阅读的时候不会卡住你的程序.你可以选其他的枚举来试试作用.以上为阅读部分.如果需要程序听你说话,则需要声明一个侦听类dim RG As SpeechLib.ISpeechRecoGrammar在初始化时将之与上面的RC建立关系,此时则必须要用withevent来声明上面的RC,因为涉及电脑听到你的语音后,会触发一个事件,并将听到的内容传递到该事件.其次,要让系统听到的解析为命令,就必须准备一个XML结构的文件来保存那些固定的命令.如果电脑在XML文件中找不到那些固定命令或同时不属于系统命令,电脑将会将其解释为听写.RG = RC.CreateGrammar '(0)
RG.CmdLoadFromFile("听到.xml", SpeechLib.SpeechLoadOption.SLODynamic)
RG.CmdSetRuleIdState(0, SpeechLib.SpeechRuleState.SGDSActive)然后写一个过程来处理听到的事件Private Sub 听到命令(ByVal StreamNumber As Integer, ByVal StreamPosition As Object, ByVal RecognitionType As SpeechLib.SpeechRecognitionType, ByVal 话语 As SpeechLib.ISpeechRecoResult) Handles RC.Recognition RC.Voice.Speak("我听到了" 话语.PhraseInfo.GetText, 11)End Sub以上为侦听部分.下面列一个XML的例文?xml version="1.0" encoding="gb2312"?
GRAMMAR LANGID="804"
RULE NAME="命令" TOPLEVEL="ACTIVE"
L
P打开播放器
P上我的QQ
P关闭你自己 /L
/RULE
/GRAMMAR要让系统正确地侦听到你说的话,前提你必须运行语音识别程序并让其激活到"正在聆听"状态.并且你必须有一个能正常使用的话筒而且保证话筒已经打开.(废话-_-|||)以上就是用VB.NET语音识别的最基本的一些操作.希望对你有帮助.更深入的内容有兴趣的话可以和我一起研究.
My.Computer.Audio.Play("SoundFile.wav")
SoundFile.wav是你要播放的声音文件的路径