Pages

Showing posts with label Dot Net. Show all posts
Showing posts with label Dot Net. Show all posts

Tuesday, 27 May 2014

Sound Recorder in C#



Hello Programmer,

Here you are going to create a Sound Recorder in C#. The Recorded sound will be saved in .wav format. So let's start;



Steps

1. Open Visual Studio -> New Project -> Windows Form Application with name
    SoundRecorder.

2. Now add 3 buttons and a  label to the empty form and design it as shown in 
    the below screenshot.



3. Now change the name and text of the added controls from the Properties dialog box;

   Control          Control Name                Text
    Button1           btnRecord                    Record
    Button2           btnStopandSave            Stop and Save
    Button3           btnPlay                        Play
    label1              label1                          Recording...

4. Now double click on the Record button and copy the below code;

            label1.Visible = true;
            mciSendString("open new type waveaudio alias Som", null, 0, 0);
            mciSendString("record Som", null, 0, 0);

5. Now double click on the Stop and Save button and copy the below code;

            label1.Visible = false;
            mciSendString("pause Som", null, 0, 0);
            SaveFileDialog save = new SaveFileDialog();
            save.Filter = "wave|*.wav";
            if (save.ShowDialog() == DialogResult.OK)
            {
                mciSendString("save Som " + save.FileName, null, 0, 0);
                mciSendString("close Som", null, 0, 0);
            }
         

6. Now double click on the  Play button and copy the below code;

           if (record == "")
            {
                OpenFileDialog open = new OpenFileDialog();
                open.Filter = "Wave|*.wav";
                if (open.ShowDialog() == DialogResult.OK) { record = open.FileName; }
            }
            mciSendString("play " + record, null, 0, 0);

7. Now double click on the  Form and copy the below code;

         label1.Visible = false;

8. Now please update your code from the complete code shown below;

Form1.cs


using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace SoundRecorder
{
    public partial class Form1 : Form
    {
        [DllImport("winmm.dll")]
        private static extern int mciSendString(string MciComando, string MciRetorno, int MciRetornoLeng, int CallBack);

        string record = "";
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            label1.Visible = false;

        }

        private void btnRecord_Click(object sender, EventArgs e)
        {
            label1.Visible = true;
            mciSendString("open new type waveaudio alias Som", null, 0, 0);
            mciSendString("record Som", null, 0, 0);
        }

        private void btnStopandSave_Click(object sender, EventArgs e)
        {
            label1.Visible = false;
            mciSendString("pause Som", null, 0, 0);
            SaveFileDialog save = new SaveFileDialog();
            save.Filter = "wave|*.wav";

            if (save.ShowDialog() == DialogResult.OK)
            {

                mciSendString("save Som " + save.FileName, null, 0, 0);
                mciSendString("close Som", null, 0, 0);
            }
        }

        private void btnPlay_Click(object sender, EventArgs e)
        {
            if (record == "")
            {
                OpenFileDialog open = new OpenFileDialog();
                open.Filter = "Wave|*.wav";
                if (open.ShowDialog() == DialogResult.OK) { record = open.FileName; }
            }
            mciSendString("play " + record, null, 0, 0);
        }
    }
}



8. Rebuild and Run the project;
  • Click on Record to start Recording.   
  • Recording label will be visible while sound is being recorded.
  • Click on Stop and Save button to Save the Recording. You will be asked for the location and filename to Save.
  • Now click on Play button to play the recorded file. You will have to select the file from the saved location.
        ENJOY Recording :-) 


OUTPUT




Conclusion

In case of any doubts / errors, please drop in a comment.


See Also

Thursday, 22 May 2014

Text to Speech in C#


Hello Programmers,



Here you are gonna learn how to convert Text to Speech in C#  i.e you are going to create a software that Talks!

So lets start;






Thursday, 15 May 2014

How to Start and Kill a Process in C#



Hi, 

Here you are gonna learn to Start and Kill a Process in C#. Suppose if you want to open / close an application such as Notepad, Calculator etc with C# codes, this tutorial will be helpful. 

Let's start;


Tuesday, 6 May 2014

File Read and Write in C#


Hi,

Here you are gonna learn File Read and Write in C#.

The below project deals with;
    a) Getting data (2 names) from the
        user.
    b) Write the data into a text file.
    c) Reading the data from the text file
        and displaying it.

so let's start

Sunday, 4 May 2014

How to Hide Folders in C#


Hi,


Hope you have read my previous post on Lock a Folder in C#. Now here you can learn How to Hide a Folder in C#. So let's start;

Wednesday, 30 April 2014

Serialize and Deserialize in C#


Hi,


Here you are gonna learn about Serialization & Deserialization in C#.

Definition

Serialization is the process of converting an object into a stream of bytes in order to store the object or transmit it to memory, a database, or a file. Its main purpose is to save the state of an object in order to be able to recreate it when needed. The reverse process is called Deserialization (From MSDN).

Thursday, 24 April 2014

Lock a Folder in C#


Hi,

Here you will learn how to lock and Unlock folders using C#. This tutorial is of good use if you are planning to create a Folder Locking Software. 


Let's start;

Tuesday, 8 April 2014

How to Change IP Address in C#


Hi Friends, 


You have learned to Get IP Address in C# 
from the last post. Here you can learn to change IP Address using C#.

Let's start;

Monday, 31 March 2014

How to get IP Address using C#


Hello All,

Here's a tutorial to get your IP Address using C#. 




N.B: Beginners please follow the link to know How to create your First Windows Form Application.

Wednesday, 26 March 2014

Media Player in C#


Hi,

You have learned to create a Music Player in C#, now here's a tutorial for creating your own Media Player in C# and press OK. 

Monday, 24 March 2014

Music Player in C#


Hi All,








Here you can learn to Create a Music Player in C#. This is a simple tutorial and even beginners can learn without any confusion.

This Player also supports video files (large files are not supported)

Monday, 17 March 2014

Digital Clock in C#

Hi Friends,


This is a simple tutorial to create a Digital Clock in c#. This is presented in a way so that even beginners can learn without any 'hiccups'. So lets start.

Thursday, 13 March 2014

OpenFileDialog in C#


Hi Friends, 

This tutorial is a continuation of First C# Windows Form Application. So now you know how to create a Windows Form Application in c#. Here you will learn how to use OpenFileDialog. OpenFileDialog is a control that allows users to browse folders and select files.

Here is a tutorial for creating an Image Viewer with OpenFileDialog. 


Steps

Thursday, 6 March 2014

First C# Windows Form Application


Hello All,

This is a very simple tutorial on how to create a Windows Form Application in c#.

Requirements

Visual Studio 2008 or higher versions.

What is Windows Forms?
Windows Forms (WinForms) is the name given to the graphical application programming interface (API) included as a part of Microsoft .NET Framework, providing access to native Microsoft Windows interface elements by wrapping the extant Windows API in managed code. (Wiki definition)

So lets start.

Thursday, 27 February 2014

WCF Tutorial for Beginners


Definition of WCF 

Windows Communication Foundation (WCF) is a framework for building service-oriented applications. Using WCF we can build secure, reliable, transacted solutions that integrate across platforms.

 

About Me

I am Tijo Tom, a Computer Engineer from India.Right from my schooling, I had a passion for Programming, PC Tricks, Virus Creation and Hacking.

I started this blog on Jan 1, 2014 to share my views and ideas with the world.

You can know more about me on