locked
Helps needed in implementing voice recorder in Windows Mobile 5.0 using .NET Compact Framework 2.0 RRS feed

  • Question

  • User2126574471 posted

    Hi guys,

    Is any of you experienced or aware of how to write a simple voice recorder program which allows you to record your voice, stop the recording, play the recorded voice and stop playing it? Anyone can help me on that? I've been trying days and nights but can't get it working still >.<"

    Any help would be highly appreciated!

    Thanks a million.

    Regards,
    Jenson

    Saturday, March 31, 2007 6:23 AM

Answers

  • User2126574471 posted

    Sorry to trouble you all so much guys. I've managed to come out with solution. I've made a stupid mistake. The codes are alright, but I just never declare a global Recorder object in a new module for my voice recording program.

    I just created a new module and give it anyname, I named it Gloabl1 as a new module and I make the below statements:

    Imports OpenNETCF.Media.WaveAudio
    Module Global1
              Public recNew As New Recorder
    End Module

    That's all I did and I managed to make it working and change the codes. Below just to share what I have done to the codes and how it work out for me. If you all need something to refer and doesnt mind to see my stupid codes, here they are:

     

    Imports System.Windows.Forms
    Imports OpenNETCF.Media.WaveAudio
    Imports System.IO
    Imports OpenNETCF.Media.SoundPlayer
    Imports System
    Imports System.Drawing
    Imports System.Collections
    Imports System.Data

    Public Class Form1
        
    Public Sub New()

              ' This call is required by the Windows Form Designer.

              InitializeComponent()

              ' Add any initialization after the InitializeComponent() call.

        End Sub

        Private Sub Record()

             If MenuItemRecord.Text <> "Stop" Then

                  'Start Recording
                  
    If File.Exists("\Storage Card\audio0001.wav") = True Then
                    
    File.Delete("\Storage Card\audio0001.wav")

                     lblTime.Text = "60"

                     tmrRecord.Interval = 1000
                     tmrRecord.Enabled =
    True

            recNew.RecordFor(File.OpenWrite("\Storage Card\audio0001.wav"), 60, SoundFormats.Mono8bit44kHz)

                     MenuItemRecord.Text = "Stop"

                     MenuItemPlay.Enabled = False

                  End If

             Else

                  'Stop recording

                  tmrRecord.Enabled = False

                  lblTime.Text = "Recording stopped."

                  recNew.Stop()

                  MenuItemRecord.Text = "Record"
                 
    MenuItemPlay.Enabled = True

              End If

          End Sub

          Private Sub player_DonePlaying()

               MenuItemPlay.Text = "Play"

          End Sub

          Private Sub Play()

               Dim p As New OpenNETCF.Media.SoundPlayer

               If MenuItemPlay.Text = "Stop" Then

                  'Stop the playback
                 
    p.Stop()
                  player_DonePlaying()

                  MenuItemPlay.Text = "Play"

               Else

                  'Playback the recorded voice clip
                 
    p.SoundLocation = "\Storage Card\audio0001.wav"
                 
    p.Play()

                  MenuItemPlay.Text = "Stop"

               End If

         End Sub

    Private Sub menuitemRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemRecord.Click

              Record()

    End Sub

     

    Private Sub mniPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemPlay.Click

              Play()

    End Sub

     

    Private Sub mniExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemExit.Click

             Me.Close()

    End Sub

     

    Private Sub tmrRecord_Timer(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrRecord.Tick

            If (lblTime.Text > 0) Then

                 lblTime.Text = CInt(lblTime.Text) - 1

            End If

    End Sub

    End Class

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 2, 2007 9:36 PM

All replies

  • User907266268 posted

    Jenson,

    Is there a specific point in which you are having problems?  Have you looked at the OpenNetCF project's extensions around audio recording?

    Cheers,
    Colin

    Saturday, March 31, 2007 3:29 PM
  • User2126574471 posted

    Hi Colin,

    Thanks for replying, I'm quite new in using OpenNetFramework and reading the APIs etc. I think my code is rather messy. I'm using VB 2005 to code the recorder program. However, I'm totally clueless how to call the recorder to stop recording, maybe my logis is wrong, I'm not sure.

    I have no problem calling the program to record, but then I can't call it to stop. The same thing apply to playing the recorded voice within the program itself. At first it works well, after I change the codes a bit (which I think does not affect the playing of the recorded clip), it's not recording at al, it does not play too. I think it has something to do with the codes that call the recorder class to record and stop the recording.

    Any clue?

    I paste my messy codes below, which I had made changes until it's not so readable and I might left out some parts too. Please helps me to check what went wrong with my codes, would you? I'm really green in this :(

    Imports System.Windows.Forms
    Imports OpenNETCF.Media.WaveAudio
    Imports System.IO
    Imports OpenNETCF.Media.SoundPlayer

    Public Class Form1
    Public Sub New()

        ' This call is required by the Windows Form Designer.

        InitializeComponent()

        lblStatus.Visible = False

        btnPlay.Enabled = False

        ' Add any initialization after the InitializeComponent() call.

    End Sub

    Private Sub btnRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRecord.Click

    If btnRecord.Text = "Record" Then
        lblStatus.Visible = True
        handleRecording()
    ElseIf btnRecord.Text = "Stop" Then
       
    lblStatus.Text = ""
       
    lblStatus.Text = "Recording Stopped"
       
    doneRecording()
    End If

    End Sub

    Private Sub doneRecording()

    btnPlay.Enabled = True
    btnRecord.Text = "Record"
    btnPlay.Text = "Play"
    lblStatus.Text = ""

    End Sub

    Private Sub playSound()

    If btnPlay.Enabled = True Then

        If File.Exists("\Storage Card\audio0001.amr") Then

            Dim path As String
           
    path = "\Storage Card\audio0001.amr"
           
    Dim p As New OpenNETCF.Media.SoundPlayer
            p.SoundLocation = path
            p.Play()
            btnPlay.Text =
    "Stop"

        Else

            MsgBox("File not found!", MsgBoxStyle.Exclamation, "Read error!")
           
    Exit Sub

        End If

    End If

    End Sub

    Private Sub handleRecording()

        btnRecord.Text = "Stop"
       
    lblStatus.Visible = True

        Dim recNew As New Recorder
       
    Dim recPath As String
       
    recPath = "\Storage Card\audio0001.amr"
       
    Dim recStream As Stream
        recStream = File.OpenWrite(recPath)

        If File.Exists(recPath) = True Then
           
    File.Delete(recPath)
       
    Else
           
    recNew.RecordFor(recStream, 30) , SoundFormats.Mono8bit44kHz)
        
       
    While btnRecord.Text = "Stop"
           
    lblStatus.Text = "Recording ..."
       
    End While
       
    recNew.Stop()

        End If

    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles

        btnExit.Click
       
    Me.Close()

    End Sub

    Private Sub btnPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlay.Click

    playSound()

    End Sub

    End Class

    Sunday, April 1, 2007 10:43 PM
  • User2126574471 posted

    I'm sorry about my previous post. It seems to me that i cannot edit my post, so I have to make a new post. This is my updated code, so now I only have problem stopping the recorder. Can you help me to check what's wrong with my codes? Anyone else can help me on this? Thanks...

    Imports System.Windows.Forms

    Imports OpenNETCF.Media.WaveAudio

    Imports System.IO

    Imports OpenNETCF.Media.SoundPlayer

    Imports System

    Imports System.Drawing

    Imports System.Collections

    Imports System.Data

     

    Public Class Form1

    Public Sub New()

    ' This call is required by the Windows Form Designer.

    InitializeComponent()

    ' Add any initialization after the InitializeComponent() call.

    End Sub

    Private Sub Record()

    Dim recNew As New Recorder

    'Try

    If MenuItemRecord.Text <> "Stop" Then

    'Dim recNew As New Recorder

    'Start Recording

    If File.Exists("\Storage Card\audio0001.wav") = True Then

    File.Delete("\Storage Card\audio0001.wav")

    Else

    lblTime.Text = String.Format("0:{0:00}", 30)

    'Dim timeLeft As String = 30

    tmrRecord.Enabled = True

    'MenuItemRecord.Text = "Stop"

    recNew.RecordFor(File.OpenWrite("\Storage Card\audio0001.wav"), 30, SoundFormats.Mono8bit44kHz)

    MenuItemRecord.Text = "Stop"

    MenuItemPlay.Enabled = False

    End If

    Else

    tmrRecord.Enabled = False

    lblTime.Text = "Recording stopped."

    'Stop Recording

    'If recNew.Recording = False Then

    'MsgBox("Recorder stop")

    'Else

    recNew.Stop()

    MenuItemRecord.Text = "Record"

    MenuItemPlay.Enabled = True

    'recorder_DoneRecording()

    'End If

     

     

    End If

    'Catch ex As Exception

    'MessageBox.Show(ex.Message)

    'End Try

    End Sub

    Private Sub recorder_DoneRecording()

    MenuItemRecord.Text = "Record"

    tmrRecord.Enabled = False

    MenuItemPlay.Enabled = True

    End Sub

    Private Sub player_DonePlaying()

    MenuItemPlay.Text = "Play"

    End Sub

    Private Sub Play()

    'Dim player As New Player

    Dim p As New OpenNETCF.Media.SoundPlayer

    If MenuItemPlay.Text = "Stop" Then

    p.Stop()

    player_DonePlaying()

    'player.Stop()

    MenuItemPlay.Text = "Play"

    Else

    'Dim s As Stream

    's = File.OpenRead("\Storage Card\audio0001.amr")

    'Playback

    p.SoundLocation = "\Storage Card\audio0001.wav"

    p.Play()

    'player.Play(File.OpenRead("\Storage Card\audio0001.amr"))

    MenuItemPlay.Text = "Stop"

    End If

    End Sub

    Private Sub menuitemRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemRecord.Click

    Record()

    End Sub

    Private Sub mniPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemPlay.Click

    Play()

    End Sub

    Private Sub mniExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemExit.Click

    Me.Close()

    End Sub

    Private Sub tmrRecord_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrRecord.Tick

    Dim timeLeft As String

    Dim i As Integer

    timeLeft = 30

    If (timeLeft > 0) Then

    For i = 0 To (timeLeft - 1)

    lblTime.Text = String.Format("0:{0:00}", timeLeft)

    timeLeft = timeLeft - 1

    Next i

    End If

    End Sub

    End Class

    Monday, April 2, 2007 4:32 AM
  • User2126574471 posted

    Sorry to trouble you all so much guys. I've managed to come out with solution. I've made a stupid mistake. The codes are alright, but I just never declare a global Recorder object in a new module for my voice recording program.

    I just created a new module and give it anyname, I named it Gloabl1 as a new module and I make the below statements:

    Imports OpenNETCF.Media.WaveAudio
    Module Global1
              Public recNew As New Recorder
    End Module

    That's all I did and I managed to make it working and change the codes. Below just to share what I have done to the codes and how it work out for me. If you all need something to refer and doesnt mind to see my stupid codes, here they are:

     

    Imports System.Windows.Forms
    Imports OpenNETCF.Media.WaveAudio
    Imports System.IO
    Imports OpenNETCF.Media.SoundPlayer
    Imports System
    Imports System.Drawing
    Imports System.Collections
    Imports System.Data

    Public Class Form1
        
    Public Sub New()

              ' This call is required by the Windows Form Designer.

              InitializeComponent()

              ' Add any initialization after the InitializeComponent() call.

        End Sub

        Private Sub Record()

             If MenuItemRecord.Text <> "Stop" Then

                  'Start Recording
                  
    If File.Exists("\Storage Card\audio0001.wav") = True Then
                    
    File.Delete("\Storage Card\audio0001.wav")

                     lblTime.Text = "60"

                     tmrRecord.Interval = 1000
                     tmrRecord.Enabled =
    True

            recNew.RecordFor(File.OpenWrite("\Storage Card\audio0001.wav"), 60, SoundFormats.Mono8bit44kHz)

                     MenuItemRecord.Text = "Stop"

                     MenuItemPlay.Enabled = False

                  End If

             Else

                  'Stop recording

                  tmrRecord.Enabled = False

                  lblTime.Text = "Recording stopped."

                  recNew.Stop()

                  MenuItemRecord.Text = "Record"
                 
    MenuItemPlay.Enabled = True

              End If

          End Sub

          Private Sub player_DonePlaying()

               MenuItemPlay.Text = "Play"

          End Sub

          Private Sub Play()

               Dim p As New OpenNETCF.Media.SoundPlayer

               If MenuItemPlay.Text = "Stop" Then

                  'Stop the playback
                 
    p.Stop()
                  player_DonePlaying()

                  MenuItemPlay.Text = "Play"

               Else

                  'Playback the recorded voice clip
                 
    p.SoundLocation = "\Storage Card\audio0001.wav"
                 
    p.Play()

                  MenuItemPlay.Text = "Stop"

               End If

         End Sub

    Private Sub menuitemRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemRecord.Click

              Record()

    End Sub

     

    Private Sub mniPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemPlay.Click

              Play()

    End Sub

     

    Private Sub mniExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemExit.Click

             Me.Close()

    End Sub

     

    Private Sub tmrRecord_Timer(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrRecord.Tick

            If (lblTime.Text > 0) Then

                 lblTime.Text = CInt(lblTime.Text) - 1

            End If

    End Sub

    End Class

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 2, 2007 9:36 PM