Audio Recorder

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • markmcgookin
    Recognized Expert Contributor
    • Dec 2006
    • 648

    Audio Recorder

    Hi Folks,

    I was hoping to get a little help here. I have recently foun the following code (here: http://www.opennetcf.o rg/forums/topic.asp?TOPIC _ID=160)

    Code:
    public class VoiceRecorder
        {
            #region API prototypes
            [DllImport("voicectl.dll", EntryPoint = "VoiceRecorder_Create")]
            private unsafe static extern IntPtr VoiceRecorder_Create(CM_VOICE_RECORDER* voicerec);
    
            [DllImport("coredll.dll", EntryPoint = "GetForegroundWindow")]
            private unsafe static extern IntPtr GetForegroundWindow();
            #endregion
    
            [StructLayout(LayoutKind.Sequential)]
            public unsafe struct CM_VOICE_RECORDER
            {
                public int cb;
                public wndStyle dwStyle;
                public int xPos;
                public int yPos;
                public IntPtr hwndParent;
                public int id;
                public char* lpszRecordFileName;
            }
    
            public enum wndStyle : uint
            {
                VRS_NO_OKCANCEL = 0x0001, // No OK/CANCLE displayed
                VRS_NO_NOTIFY = 0x0002, // No parent Notifcation
                VRS_MODAL = 0x0004, // Control is Modal    
                VRS_NO_OK = 0x0008, // No OK displayed
                VRS_NO_RECORD = 0x0010, // No RECORD button displayed
                VRS_PLAY_MODE = 0x0020, // Immediately play supplied file when launched
                VRS_NO_MOVE = 0x0040, // Grip is removed and cannot be moved around by the user
                VRS_RECORD_MODE = 0x0080, // Immediately record when launched
                VRS_STOP_DISMISS = 0x0100 // Dismiss control when stopped
            }
    
            private unsafe CM_VOICE_RECORDER _VoiceRec;
            private IntPtr _hRecorder;
            private string wavFile = @"\My Documents\~VRec_0.wav";
    
            private IntPtr _Hwnd = (IntPtr)0;
    
            public IntPtr Hwnd
            {
                get { return _Hwnd; }
                set
                {
                    _VoiceRec.hwndParent = value;
                    _Hwnd = value;
                }
            }
    
            public unsafe VoiceRecorder()
            {
                _hRecorder = new IntPtr();
                char[] temp = new char[32];
    
                this.Hwnd = GetForegroundWindow();
    
                // Populate temp with the file path of the WAV file            
                Buffer.BlockCopy(wavFile.ToCharArray(), 0, temp, 0, 2 * wavFile.Length);
    
                fixed (char* lpszFileName = temp)
                {
                    _VoiceRec = new CM_VOICE_RECORDER();
    
                    _VoiceRec.hwndParent = _Hwnd;
                    _VoiceRec.dwStyle = wndStyle.VRS_NO_MOVE | wndStyle.VRS_MODAL;
                    _VoiceRec.cb = (int)Marshal.SizeOf(_VoiceRec);
                    _VoiceRec.xPos = -1;
                    _VoiceRec.yPos = -1;
                    _VoiceRec.lpszRecordFileName = lpszFileName;
                }
            }
    
            // Show the voice recorder
            public unsafe void Show()
            {
                fixed (CM_VOICE_RECORDER* _VoiceRecPtr = &_VoiceRec)
                {
                    _hRecorder = VoiceRecorder_Create(_VoiceRecPtr);
                }
            }
        }
    }
    which is for creating a voice/audio recorder on a WM5 PDA. I have included the code into my project in a VoiceRecorder.c s class, and have invoked it from the main code (i.e. VoiceRecorder vr = new VoiceRecorder() ; vr.show() ) and the voice recorder app appears on screen, and beeps when I hit record, but there doesnt seem to be any file being created, nor is there any functions for playback. I was wondering if anyone could help me out here, as I really want to include this in my application. If anyone has any other ideas on a good way to include a voice recording feature from c# code I would greatly appreciate it!

    Cheers folks,

    Mark
  • RedSon
    Recognized Expert Expert
    • Jan 2007
    • 4980

    #2
    Who wrote voicectl.dll? And do you have access to the source code for it?

    Comment

    • markmcgookin
      Recognized Expert Contributor
      • Dec 2006
      • 648

      #3
      Originally posted by RedSon
      Who wrote voicectl.dll? And do you have access to the source code for it?
      It's a standard component within Windows Mobile 5 (NB I think i hit the wrong button earlier and reported this post and not replying! Sorry!)

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        Given these 2 lines

        [code=c]
        private string wavFile = @"\My Documents\~VRec _0.wav";
        [/code]
        [code=c]
        char[] temp = new char[32];
        [/code]

        I can't help feeling that you have a file path/name error. I know nothing of cs but if the @ in the first statement equates to a balnk string then the path to the file is obviously invalid.

        On the other hand assuming that the @ in the first statement equates to the current users directory (making the path valid) then the length of the wavFile is going to be rather longer than the 32 characters assigned to temp;

        Either way you seem to have an error around you file path/name.

        Comment

        Working...