Tuesday, November 24, 2009

Voice recording wince smart device mobile application

Voice recording wince mobile application - While working on mobile projects in most of the scenario there will be a requirement for voice recording at least 75%. I have searched a lot to use dot net compact frameworks dll but i couldn't at last i figured it is not possible using compact frameworks dll.

We can achieve the same thing using pinvoke i.e. Platform Invoke. I will just place the sample code so that you can follow up.

Read this post first before proceeding as you need to know about opennetcf

Code:



create a new form named frmVoice.vb
place button btnstart

 btnstart onclick event
************** START ****************

Private audioRecorder As OpenNETCF.Media.WaveAudio.Recorder
Dim voicefolder As String = "\My Documents\Voice"
Dim voicefile As String = voicefolder + "\Record1.wav"
Const RECORD_DURATION As Integer = 45

 If System.IO.Directory.Exists(voicefolder) = False Then
                System.IO.Directory.CreateDirectory(voicefolder)
            Else
                Dim s As String
                For Each s In System.IO.Directory.GetFiles(voicefolder)
                    System.IO.File.Delete(s)
                Next s
            End If

            Dim fs As FileStream = File.Create(voicefile)
            fs.Close()


            Dim audioStream As System.IO.Stream

            audioStream = System.IO.File.OpenWrite(voicefile)
            audioRecorder = New OpenNETCF.Media.WaveAudio.Recorder

            '---save the audio to stream---
            audioRecorder.RecordFor( _
               audioStream, _
               RECORD_DURATION, _
               OpenNETCF.Media.WaveAudio.SoundFormats.Mono16bit11kHz)



place another button stop
on stop click event

 audioRecorder.Stop()



**************   END   ****************

No comments:

Post a Comment