大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
蜂鸣器编程的话,有个API函数,VB中的声明为
创新互联公司是一家以重庆网站建设公司、网页设计、品牌设计、软件运维、seo优化排名、小程序App开发等移动开发为一体互联网公司。已累计为纯水机等众行业中小客户提供优质的互联网建站和软件开发服务。
Declare Function Beep Lib "kernel32" Alias "Beep" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long
调用方法是Beep 声音频率,持续时间(毫秒为单位)
比如 beep 2000,1000
如果是声卡编程的话,也有相应的API函数,比如你可以用DirectSound(也就是DirectX的一部分),功能比较强大,也很专业。事实上,如果你使用的是专业级的声卡和音响设备,它可以在一定范围内回放出超出人耳听觉范围的声音。当然也可以用简单一点的API,以下是几个需要的函数:
Private Declare Function midiOutGetDevCaps Lib "winmm.dll" Alias "midiOutGetDevCapsA" (ByVal uDeviceID As Long, lpCaps As MIDIOUTCAPS, ByVal uSize As Long) As Long
Private Declare Function midiOutGetNumDevs Lib "winmm" () As Integer
Private Declare Function MIDIOutOpen Lib "winmm.dll" Alias "midiOutOpen" (lphMidiOut As Long, ByVal uDeviceID As Long, ByVal dwCallback As Long, ByVal dwInstance As Long, ByVal dwFlags As Long) As Long
Private Declare Function midiOutClose Lib "winmm.dll" (ByVal hMidiOut As Long) As Long
Private Declare Function midiOutShortMsg Lib "winmm.dll" (ByVal hMidiOut As Long, ByVal dwMsg As Long) As Long
Private Declare Function midiOutGetErrorText Lib "winmm.dll" Alias "midiOutGetErrorTextA" (ByVal err As Long, ByVal lpText As String, ByVal uSize As Long) As Long
Private Const MAXERRORLENGTH = 128 ' max error text length (including NULL)
Private Const MIDIMAPPER = (-1)
Private Const MIDI_MAPPER = (-1)
'MIDIOUTCAPS结构描述了Musical Instrument Digital Interface(MIDI)输入设备的性能
Type MIDIOUTCAPS
wMid As Integer
wPid As Integer ' 产品 ID
vDriverVersion As Long ' 设备版本
szPname As String * 32 ' 设备 name
wTechnology As Integer ' 设备类型
wVoices As Integer
wNotes As Integer
wChannelMask As Integer
dwSupport As Long
End Type
Public Sub note_on(ch As Integer, ByVal kk As Integer, v As Integer)
' 发音主函数。参数分别为通道编号,音调,速度
Call midi_outshort(H90 + ch, kk, v)
End Sub
Sub midi_outshort(b1 As Integer, b2 As Integer, b3 As Integer)
Dim midi_error As Integer
midi_error = midiOutShortMsg(hMidi, b3 * H10000 + b2 * H100 + b1)
If Not midi_error = 0 Then
Call midi_outerr(midi_error)
End If
End Sub
Sub midi_outerr(ByVal midi_error As Integer)
Dim s As String
Dim x As Integer
s = Space(MAXERRORLENGTH)
x = midiOutGetErrorText(midi_error, s, MAXERRORLENGTH)
MsgBox s
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim s As Object
s = CreateObject("sapi.spvoice")
s.speak("speak")
End Sub
Private Declare Function mciExecute Lib "winmm.dll" (ByVal lpstrCommand As String) As Long
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call mciExecute("play F:\MUSIC\WMA\guitar\强调乐队-无声的叹息.mp3 ")
End Sub
复制可不怎么好吧,那些dll你都要有才行,vb.net做安装程序也不麻烦,只要添加一个新项目--安装向导,根据提示按下去就是了
哎~~~都说得很清楚了,你还......再给个提示吧,用timeofday来提取当前时间,和自定义时间对比
首先添加一个系统的语音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语音识别的最基本的一些操作.希望对你有帮助.更深入的内容有兴趣的话可以和我一起研究.