Results 1 to 16 of 16

Thread: Sound Recorder

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    106

    Sound Recorder

    A simple Sound Recorder~

    1. Add Three buttons (button1, button2, button3) and a label (label1) to the form.
    2. Set the Text of Button1 to Start, Button2 to Stop, and Button3 to Play.
    3. Add this code:

    VB.NET Code:
    1. Public Class Form1
    2.  
    3.     Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
    4.  
    5.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    6.  
    7.         Button1.Enabled = False
    8.  
    9.         Button2.Enabled = True
    10.  
    11.         mciSendString("open new Type waveaudio Alias recsound", "", 0, 0)
    12.  
    13.         mciSendString("record recsound", "", 0, 0)
    14.  
    15.         Label1.Text = "Recording..."
    16.  
    17.         Label1.Visible = True
    18.  
    19.     End Sub
    20.  
    21.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    22.  
    23.         Button1.Enabled = True
    24.  
    25.         Button2.Enabled = False
    26.  
    27.         Button3.Enabled = True
    28.  
    29.         mciSendString("save recsound c:\recsound.wav", "", 0, 0)
    30.  
    31.         mciSendString("close recsound", "", 0, 0)
    32.  
    33.         MsgBox("File Created: C:\recsound.wav")
    34.  
    35.         Label1.Text = "Stopped..."
    36.  
    37.         Label1.Visible = False
    38.  
    39.         My.Computer.Audio.Stop()
    40.  
    41.     End Sub
    42.  
    43.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    44.  
    45.         Label1.Text = "Playing..."
    46.  
    47.         Label1.Visible = True
    48.  
    49.         My.Computer.Audio.Play("c:\recsound.wav", AudioPlayMode.Background)
    50.  
    51.     End Sub
    52. End Class
    Attached Images Attached Images  
    Attached Files Attached Files

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Sound Recorder

    What is the point of having both a "Start" and "Play" button?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    106

    Re: Sound Recorder

    start starts the recording...and play plays it back...

  4. #4
    Frenzied Member obi1kenobi's Avatar
    Join Date
    Aug 2007
    Posts
    1,091

    Re: Sound Recorder

    Does this work on Vista/Win7? Because I thought that the APIs needed to record audio output in real time were disabled in Vista and Win7 in order to prevent people recording music from internet radio and similar services...

    EDIT: I also see that you have executable files in your archive, which is in violation of CodeBank policy. You should remove the bin and obj folders from the archive.
    Last edited by obi1kenobi; Jul 17th, 2010 at 05:06 AM. Reason: executable files in submission
    Please rate helpful ppl's posts. It's the best 'thank you' you can give

  5. #5
    Frenzied Member obi1kenobi's Avatar
    Join Date
    Aug 2007
    Posts
    1,091

    Re: Sound Recorder

    First of all, you need elevatetion (admin permissions) to save to C:\ in Vista and Win7, so your app crashes when saving without that.

    Second of all, the quality of the recording is poor to the point of it being unusable... I hope there is a way to change the output format and/or the bitrate...
    Please rate helpful ppl's posts. It's the best 'thank you' you can give

  6. #6
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Sound Recorder

    Quote Originally Posted by obi1kenobi
    First of all, you need elevatetion (admin permissions) to save to C:\ in Vista and Win7, so your app crashes when saving without that.
    So change the path =P Sheesh.

    Do you get poor recording? I don't...

  7. #7
    Frenzied Member obi1kenobi's Avatar
    Join Date
    Aug 2007
    Posts
    1,091

    Re: Sound Recorder

    Quote Originally Posted by minitech View Post
    So change the path =P Sheesh.

    Do you get poor recording? I don't...
    I did change it, but I can't change it for him in the code that's part of his first post. It's called reporting a problem for a reason...

    Regarding the recording quality, what OS are you using? Mine's Vista SP2.
    Please rate helpful ppl's posts. It's the best 'thank you' you can give

  8. #8
    Fanatic Member namrekka's Avatar
    Join Date
    Feb 2005
    Location
    Netherlands
    Posts
    639

    Re: Sound Recorder

    Problem here is indeed saving at the wrong location.

    Does this work on Vista/Win7? Because I thought that the APIs needed to record audio output in real time were disabled in Vista and Win7 in order to prevent people recording music from internet radio and similar services...
    Yes it works on Vista/W7 even 64b.

    Regarding the recording quality, what OS are you using? Mine's Vista SP2.
    Its not depending of the OS but the default settings of of recording with MCI and your soundcard. Default the sample rate is 11025 and 8bits. You can change these settings with "mciSendString"
    http://msdn.microsoft.com/en-us/library/ms713255.aspx

  9. #9
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Sound Recorder

    Quote Originally Posted by obi1kenobi View Post
    I did change it, but I can't change it for him in the code that's part of his first post. It's called reporting a problem for a reason...

    Regarding the recording quality, what OS are you using? Mine's Vista SP2.
    This is the CodeBank because you can modify the code. Think of the path as a placeholder.

    I'm using XP SP3.

  10. #10

  11. #11
    Frenzied Member obi1kenobi's Avatar
    Join Date
    Aug 2007
    Posts
    1,091

    Re: Sound Recorder

    Quote Originally Posted by minitech View Post
    This is the CodeBank because you can modify the code. Think of the path as a placeholder.

    I'm using XP SP3.
    I feel like I might have been misunderstood... I know that the path is a placeholder and that this is the CodeBank and everything... My point was that the path was hardcoded into the compiled application that was included in the post and if someone downloaded it and ran it on Vista/Win7, the application would crash, failing to demonstrate it's purpose. That might prompt this person to abandon this code, thinking that it doesn't work, when in fact it does. Anyway, it's not that important now Just wanted to clear it up a bit...
    Please rate helpful ppl's posts. It's the best 'thank you' you can give

  12. #12
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Sound Recorder

    ! Okay, that's what you meant sorry.
    You're not supposed to have compiled programs in the CodeBank, though.

  13. #13
    Frenzied Member obi1kenobi's Avatar
    Join Date
    Aug 2007
    Posts
    1,091

    Re: Sound Recorder

    Quote Originally Posted by minitech View Post
    ! Okay, that's what you meant sorry.
    You're not supposed to have compiled programs in the CodeBank, though.
    It's ok, I'm glad we straightened it out
    Please rate helpful ppl's posts. It's the best 'thank you' you can give

  14. #14
    New Member
    Join Date
    Apr 2013
    Posts
    2

    Re: Sound Recorder

    hi , thanks for the code .. it's work correctly ..
    but if i want to make the user specify where to save the sound .. what should i do ??

  15. #15
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Sound Recorder

    Try this!

    vb.net Code:
    1. Public Class Form1
    2.  
    3.     Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
    4.  
    5.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    6.  
    7.         Button1.Enabled = False
    8.  
    9.         Button2.Enabled = True
    10.  
    11.         mciSendString("open new Type waveaudio Alias recsound", "", 0, 0)
    12.  
    13.         mciSendString("record recsound", "", 0, 0)
    14.  
    15.         Label1.Text = "Recording..."
    16.  
    17.         Label1.Visible = True
    18.  
    19.     End Sub
    20.  
    21.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    22.  
    23.         Button1.Enabled = True
    24.  
    25.         Button2.Enabled = False
    26.  
    27.         Button3.Enabled = True
    28.         SaveFileDialog1.ShowDialog()
    29.         mciSendString("save recsound " & SaveFileDialog1.FileName, "", 0, 0)
    30.  
    31.         mciSendString("close recsound", "", 0, 0)
    32.  
    33.         MsgBox("File Created: " & SaveFileDialog1.FileName)
    34.  
    35.         Label1.Text = "Stopped..."
    36.  
    37.         Label1.Visible = False
    38.  
    39.         My.Computer.Audio.Stop()
    40.  
    41.     End Sub
    42.  
    43.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    44.         SaveFileDialog1.ShowDialog()
    45.         Label1.Text = "Playing..."
    46.  
    47.         Label1.Visible = True
    48.  
    49.         My.Computer.Audio.Play(SaveFileDialog1.FileName, AudioPlayMode.Background)
    50.  
    51.     End Sub
    52.  
    53.     Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    54.         Button1.Text = "Start"
    55.         Button2.Text = "Stop"
    56.         Button3.Text = "Play"
    57.     End Sub
    58. End Class

    Modified the original code so that it uses a save dialog.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  16. #16
    New Member
    Join Date
    Apr 2013
    Posts
    2

    Thumbs up Re: Sound Recorder

    Thanx a lot for your help ..
    it worked perfectly ^_^"

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width