Answered by:
Helps needed in implementing voice recorder in Windows Mobile 5.0 using .NET Compact Framework 2.0

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,
JensonSaturday, 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 ModuleThat'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.DataPublic
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
True
tmrRecord.Enabled =recNew.RecordFor(File.OpenWrite(
"\Storage Card\audio0001.wav"), 60, SoundFormats.Mono8bit44kHz)MenuItemRecord.Text =
"Stop"MenuItemPlay.Enabled =
False End If Else 'Stop recordingtmrRecord.Enabled =
FalselblTime.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 SubPrivate 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
lblTime.Text =
CInt(lblTime.Text) - 1 End If End SubEnd
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,
ColinSaturday, 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.SoundPlayerPublic
Class Form1
Public Sub New() ' This call is required by the Windows Form Designer.InitializeComponent()
lblStatus.Visible =
FalsebtnPlay.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" ElseMsgBox(
"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.ClickplaySound()
End SubEnd
ClassSunday, 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.FormsImports
OpenNETCF.Media.WaveAudioImports
System.IOImports
OpenNETCF.Media.SoundPlayerImports
SystemImports
System.DrawingImports
System.CollectionsImports
System.DataPublic
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 ThenFile.Delete(
"\Storage Card\audio0001.wav") ElselblTime.Text =
String.Format("0:{0:00}", 30) 'Dim timeLeft As String = 30tmrRecord.Enabled =
True 'MenuItemRecord.Text = "Stop"recNew.RecordFor(File.OpenWrite(
"\Storage Card\audio0001.wav"), 30, SoundFormats.Mono8bit44kHz)MenuItemRecord.Text =
"Stop"MenuItemPlay.Enabled =
False End If ElsetmrRecord.Enabled =
FalselblTime.Text =
"Recording stopped." 'Stop Recording 'If recNew.Recording = False Then 'MsgBox("Recorder stop") 'ElserecNew.Stop()
MenuItemRecord.Text =
"Record"MenuItemPlay.Enabled =
True 'recorder_DoneRecording() 'End IfMenuItemRecord.Text =
"Record"tmrRecord.Enabled =
FalseMenuItemPlay.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" Thenp.Stop()
player_DonePlaying()
'player.Stop()MenuItemPlay.Text =
"Play" Else 'Dim s As Stream 's = File.OpenRead("\Storage Card\audio0001.amr") 'Playbackp.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.ClickRecord()
End Sub Private Sub mniPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemPlay.ClickPlay()
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 IntegertimeLeft = 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 SubEnd
ClassMonday, 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 ModuleThat'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.DataPublic
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
True
tmrRecord.Enabled =recNew.RecordFor(File.OpenWrite(
"\Storage Card\audio0001.wav"), 60, SoundFormats.Mono8bit44kHz)MenuItemRecord.Text =
"Stop"MenuItemPlay.Enabled =
False End If Else 'Stop recordingtmrRecord.Enabled =
FalselblTime.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 SubPrivate 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
lblTime.Text =
CInt(lblTime.Text) - 1 End If End SubEnd
Class- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, April 2, 2007 9:36 PM