What are the errors in my code with NAudio?












0















There is such a task:
Need to implement a program. The program has a text box and the ability to open text files and paste text from a file into this text box.
Also, the program should record audio. For this, I use the NAudio library.
When you press CTRL + 1, audio is recording. When you press CTRL + 2, stop record.
Each file is recorded by record number. The number is incremented after each entry.
I implemented the program correctly, I took the code from NAudio from the article about recording audio in C # through NAudio. There was a write code right there in the button event, but I implemented separate methods.
As a result, Visual Studio produces a list of errors.
Please help me figure it out.
Form File Code:



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using NAudio.Wave;
using NAudio.FileFormats;
using NAudio.CoreAudioApi;
using NAudio;
 
namespace RecordBooks
{
    public partial class Form1 : Form
    {
        WaveIn waveIn;
        WaveFileWriter writer;
        string recordFile = "";
        int numberRecords = 0;
        public Form1()
        {
            InitializeComponent();
            KeyPreview = true;
            KeyDown += Form1_KeyDown;
        }
 
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control && e.KeyCode == Keys.D1)
            {
                StartRecording();
            }
            else if (e.Control && e.KeyCode == Keys.D2)
            {
                if (waveIn != null)
                {
                    StopRecording();
                }
            }
        }
 
        void waveIn_DataAvailable(object sender, WaveInEventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new EventHandler<WaveInEventArgs>(waveIn_DataAvailable), sender, e);
            }
            else
            {
                writer.WriteData(e.Buffer, 0, e.BytesRecorded);
            }
        }
 
        void StartRecording()
        {
            try
            {
                waveIn = new WaveIn();
                waveIn.DeviceNumber = 0;
                waveIn.DataAvailable += waveIn_DataAvailable;
                waveIn.RecordingStopped += new EventHandler(waveIn_RecordingStopped);
                waveIn.WaveFormat = new WaveFormat(8000, 1);
                recordFile = numberRecords + ".wav";
                writer = new WaveFileWriter(recordFile);
                waveIn.StartRecording();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
 
            void StopRecording()
            {
                waveIn.StopRecording();
                numberRecords += 1;
            }
 
            void waveIn_RecordingStopped(object sender, EventArgs e)
            {
                if (this.InvokeRequired)
                {
                    this.BeginInvoke(new EventHandler(waveIn_RecordingStopped), sender, e);
                }
                else
                {
                    waveIn.Dispose();
                    waveIn = null;
                    writer.Close();
                    writer = null;
                }
            }
 
            void menuNew_Click(object sender, EventArgs e)
            {
                richTextBox1.Clear();
                numberRecords = 0;
            }
 
            void menuExit_Click(object sender, EventArgs e)
            {
                Application.Exit();
            }
 
            void menuOpen_Click(object sender, EventArgs e)
            {
                if (openFileDialog1.ShowDialog() == DialogResult.OK && openFileDialog1.FileName.Length > 0)
                {
                    richTextBox1.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.PlainText);
                    numberRecords = 0;
                }
            }
 
            void menuSave_Click(object sender, EventArgs e)
            {
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    richTextBox1.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText);
                }
            }
        }
    }
}









share|improve this question


















  • 1





    Could you please show the errors you get?

    – Klaus Gütter
    Nov 24 '18 at 13:27











  • i.paste.pics/2f7a200fbd070b1f2b0a616b29197dca.png

    – John Berden
    Nov 24 '18 at 14:07
















0















There is such a task:
Need to implement a program. The program has a text box and the ability to open text files and paste text from a file into this text box.
Also, the program should record audio. For this, I use the NAudio library.
When you press CTRL + 1, audio is recording. When you press CTRL + 2, stop record.
Each file is recorded by record number. The number is incremented after each entry.
I implemented the program correctly, I took the code from NAudio from the article about recording audio in C # through NAudio. There was a write code right there in the button event, but I implemented separate methods.
As a result, Visual Studio produces a list of errors.
Please help me figure it out.
Form File Code:



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using NAudio.Wave;
using NAudio.FileFormats;
using NAudio.CoreAudioApi;
using NAudio;
 
namespace RecordBooks
{
    public partial class Form1 : Form
    {
        WaveIn waveIn;
        WaveFileWriter writer;
        string recordFile = "";
        int numberRecords = 0;
        public Form1()
        {
            InitializeComponent();
            KeyPreview = true;
            KeyDown += Form1_KeyDown;
        }
 
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control && e.KeyCode == Keys.D1)
            {
                StartRecording();
            }
            else if (e.Control && e.KeyCode == Keys.D2)
            {
                if (waveIn != null)
                {
                    StopRecording();
                }
            }
        }
 
        void waveIn_DataAvailable(object sender, WaveInEventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new EventHandler<WaveInEventArgs>(waveIn_DataAvailable), sender, e);
            }
            else
            {
                writer.WriteData(e.Buffer, 0, e.BytesRecorded);
            }
        }
 
        void StartRecording()
        {
            try
            {
                waveIn = new WaveIn();
                waveIn.DeviceNumber = 0;
                waveIn.DataAvailable += waveIn_DataAvailable;
                waveIn.RecordingStopped += new EventHandler(waveIn_RecordingStopped);
                waveIn.WaveFormat = new WaveFormat(8000, 1);
                recordFile = numberRecords + ".wav";
                writer = new WaveFileWriter(recordFile);
                waveIn.StartRecording();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
 
            void StopRecording()
            {
                waveIn.StopRecording();
                numberRecords += 1;
            }
 
            void waveIn_RecordingStopped(object sender, EventArgs e)
            {
                if (this.InvokeRequired)
                {
                    this.BeginInvoke(new EventHandler(waveIn_RecordingStopped), sender, e);
                }
                else
                {
                    waveIn.Dispose();
                    waveIn = null;
                    writer.Close();
                    writer = null;
                }
            }
 
            void menuNew_Click(object sender, EventArgs e)
            {
                richTextBox1.Clear();
                numberRecords = 0;
            }
 
            void menuExit_Click(object sender, EventArgs e)
            {
                Application.Exit();
            }
 
            void menuOpen_Click(object sender, EventArgs e)
            {
                if (openFileDialog1.ShowDialog() == DialogResult.OK && openFileDialog1.FileName.Length > 0)
                {
                    richTextBox1.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.PlainText);
                    numberRecords = 0;
                }
            }
 
            void menuSave_Click(object sender, EventArgs e)
            {
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    richTextBox1.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText);
                }
            }
        }
    }
}









share|improve this question


















  • 1





    Could you please show the errors you get?

    – Klaus Gütter
    Nov 24 '18 at 13:27











  • i.paste.pics/2f7a200fbd070b1f2b0a616b29197dca.png

    – John Berden
    Nov 24 '18 at 14:07














0












0








0








There is such a task:
Need to implement a program. The program has a text box and the ability to open text files and paste text from a file into this text box.
Also, the program should record audio. For this, I use the NAudio library.
When you press CTRL + 1, audio is recording. When you press CTRL + 2, stop record.
Each file is recorded by record number. The number is incremented after each entry.
I implemented the program correctly, I took the code from NAudio from the article about recording audio in C # through NAudio. There was a write code right there in the button event, but I implemented separate methods.
As a result, Visual Studio produces a list of errors.
Please help me figure it out.
Form File Code:



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using NAudio.Wave;
using NAudio.FileFormats;
using NAudio.CoreAudioApi;
using NAudio;
 
namespace RecordBooks
{
    public partial class Form1 : Form
    {
        WaveIn waveIn;
        WaveFileWriter writer;
        string recordFile = "";
        int numberRecords = 0;
        public Form1()
        {
            InitializeComponent();
            KeyPreview = true;
            KeyDown += Form1_KeyDown;
        }
 
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control && e.KeyCode == Keys.D1)
            {
                StartRecording();
            }
            else if (e.Control && e.KeyCode == Keys.D2)
            {
                if (waveIn != null)
                {
                    StopRecording();
                }
            }
        }
 
        void waveIn_DataAvailable(object sender, WaveInEventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new EventHandler<WaveInEventArgs>(waveIn_DataAvailable), sender, e);
            }
            else
            {
                writer.WriteData(e.Buffer, 0, e.BytesRecorded);
            }
        }
 
        void StartRecording()
        {
            try
            {
                waveIn = new WaveIn();
                waveIn.DeviceNumber = 0;
                waveIn.DataAvailable += waveIn_DataAvailable;
                waveIn.RecordingStopped += new EventHandler(waveIn_RecordingStopped);
                waveIn.WaveFormat = new WaveFormat(8000, 1);
                recordFile = numberRecords + ".wav";
                writer = new WaveFileWriter(recordFile);
                waveIn.StartRecording();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
 
            void StopRecording()
            {
                waveIn.StopRecording();
                numberRecords += 1;
            }
 
            void waveIn_RecordingStopped(object sender, EventArgs e)
            {
                if (this.InvokeRequired)
                {
                    this.BeginInvoke(new EventHandler(waveIn_RecordingStopped), sender, e);
                }
                else
                {
                    waveIn.Dispose();
                    waveIn = null;
                    writer.Close();
                    writer = null;
                }
            }
 
            void menuNew_Click(object sender, EventArgs e)
            {
                richTextBox1.Clear();
                numberRecords = 0;
            }
 
            void menuExit_Click(object sender, EventArgs e)
            {
                Application.Exit();
            }
 
            void menuOpen_Click(object sender, EventArgs e)
            {
                if (openFileDialog1.ShowDialog() == DialogResult.OK && openFileDialog1.FileName.Length > 0)
                {
                    richTextBox1.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.PlainText);
                    numberRecords = 0;
                }
            }
 
            void menuSave_Click(object sender, EventArgs e)
            {
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    richTextBox1.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText);
                }
            }
        }
    }
}









share|improve this question














There is such a task:
Need to implement a program. The program has a text box and the ability to open text files and paste text from a file into this text box.
Also, the program should record audio. For this, I use the NAudio library.
When you press CTRL + 1, audio is recording. When you press CTRL + 2, stop record.
Each file is recorded by record number. The number is incremented after each entry.
I implemented the program correctly, I took the code from NAudio from the article about recording audio in C # through NAudio. There was a write code right there in the button event, but I implemented separate methods.
As a result, Visual Studio produces a list of errors.
Please help me figure it out.
Form File Code:



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using NAudio.Wave;
using NAudio.FileFormats;
using NAudio.CoreAudioApi;
using NAudio;
 
namespace RecordBooks
{
    public partial class Form1 : Form
    {
        WaveIn waveIn;
        WaveFileWriter writer;
        string recordFile = "";
        int numberRecords = 0;
        public Form1()
        {
            InitializeComponent();
            KeyPreview = true;
            KeyDown += Form1_KeyDown;
        }
 
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control && e.KeyCode == Keys.D1)
            {
                StartRecording();
            }
            else if (e.Control && e.KeyCode == Keys.D2)
            {
                if (waveIn != null)
                {
                    StopRecording();
                }
            }
        }
 
        void waveIn_DataAvailable(object sender, WaveInEventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new EventHandler<WaveInEventArgs>(waveIn_DataAvailable), sender, e);
            }
            else
            {
                writer.WriteData(e.Buffer, 0, e.BytesRecorded);
            }
        }
 
        void StartRecording()
        {
            try
            {
                waveIn = new WaveIn();
                waveIn.DeviceNumber = 0;
                waveIn.DataAvailable += waveIn_DataAvailable;
                waveIn.RecordingStopped += new EventHandler(waveIn_RecordingStopped);
                waveIn.WaveFormat = new WaveFormat(8000, 1);
                recordFile = numberRecords + ".wav";
                writer = new WaveFileWriter(recordFile);
                waveIn.StartRecording();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
 
            void StopRecording()
            {
                waveIn.StopRecording();
                numberRecords += 1;
            }
 
            void waveIn_RecordingStopped(object sender, EventArgs e)
            {
                if (this.InvokeRequired)
                {
                    this.BeginInvoke(new EventHandler(waveIn_RecordingStopped), sender, e);
                }
                else
                {
                    waveIn.Dispose();
                    waveIn = null;
                    writer.Close();
                    writer = null;
                }
            }
 
            void menuNew_Click(object sender, EventArgs e)
            {
                richTextBox1.Clear();
                numberRecords = 0;
            }
 
            void menuExit_Click(object sender, EventArgs e)
            {
                Application.Exit();
            }
 
            void menuOpen_Click(object sender, EventArgs e)
            {
                if (openFileDialog1.ShowDialog() == DialogResult.OK && openFileDialog1.FileName.Length > 0)
                {
                    richTextBox1.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.PlainText);
                    numberRecords = 0;
                }
            }
 
            void menuSave_Click(object sender, EventArgs e)
            {
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    richTextBox1.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText);
                }
            }
        }
    }
}






c# naudio






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 24 '18 at 13:14









John BerdenJohn Berden

62




62








  • 1





    Could you please show the errors you get?

    – Klaus Gütter
    Nov 24 '18 at 13:27











  • i.paste.pics/2f7a200fbd070b1f2b0a616b29197dca.png

    – John Berden
    Nov 24 '18 at 14:07














  • 1





    Could you please show the errors you get?

    – Klaus Gütter
    Nov 24 '18 at 13:27











  • i.paste.pics/2f7a200fbd070b1f2b0a616b29197dca.png

    – John Berden
    Nov 24 '18 at 14:07








1




1





Could you please show the errors you get?

– Klaus Gütter
Nov 24 '18 at 13:27





Could you please show the errors you get?

– Klaus Gütter
Nov 24 '18 at 13:27













i.paste.pics/2f7a200fbd070b1f2b0a616b29197dca.png

– John Berden
Nov 24 '18 at 14:07





i.paste.pics/2f7a200fbd070b1f2b0a616b29197dca.png

– John Berden
Nov 24 '18 at 14:07












1 Answer
1






active

oldest

votes


















0














You did not close the method StartRecording() with a }. Therefore all following methods are local to StartRecording and not visible outside.



void StartRecording()
{
try
{
waveIn = new WaveIn();
waveIn.DeviceNumber = 0;
waveIn.DataAvailable += waveIn_DataAvailable;
waveIn.RecordingStopped += new EventHandler(waveIn_RecordingStopped);
waveIn.WaveFormat = new WaveFormat(8000, 1);
recordFile = numberRecords + ".wav";
writer = new WaveFileWriter(recordFile);
waveIn.StartRecording();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
} // <<<-- this was missing

void StopRecording()
{
waveIn.StopRecording();
numberRecords += 1;
}





share|improve this answer


























  • Errors remained

    – John Berden
    Nov 24 '18 at 14:59











  • I updated my answer to be more clear. Do you get the same error messages? If they are different now, please post the new ones (better edit your question for this than adding another comment, also better add the error messages as text, not as picture).

    – Klaus Gütter
    Nov 24 '18 at 15:32











  • Error CS0029 Cannot implicitly convert type 'System.EventHandler' to 'System.EventHandler<NAudio.Wave.StoppedEventArgs>' RecordBooks

    – John Berden
    Nov 24 '18 at 18:12











  • The error message also includes a line number; and double-clicking on the error message will get you to the offending line in the visual studio code editor. Probably it is this one: waveIn.RecordingStopped += new EventHandler(waveIn_RecordingStopped);; change it to waveIn.RecordingStopped += waveIn_RecordingStopped; and alco correct the method signature of waveIn_RecordingStopped to void waveIn_RecordingStopped(object sender, StoppedEventArgs e)

    – Klaus Gütter
    Nov 25 '18 at 6:45













  • CS0123 No overload for 'waveIn_RecordingStopped' matches delegate 'EventHandler' RecordBooks Line 86

    – John Berden
    Nov 26 '18 at 12:46











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53458516%2fwhat-are-the-errors-in-my-code-with-naudio%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You did not close the method StartRecording() with a }. Therefore all following methods are local to StartRecording and not visible outside.



void StartRecording()
{
try
{
waveIn = new WaveIn();
waveIn.DeviceNumber = 0;
waveIn.DataAvailable += waveIn_DataAvailable;
waveIn.RecordingStopped += new EventHandler(waveIn_RecordingStopped);
waveIn.WaveFormat = new WaveFormat(8000, 1);
recordFile = numberRecords + ".wav";
writer = new WaveFileWriter(recordFile);
waveIn.StartRecording();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
} // <<<-- this was missing

void StopRecording()
{
waveIn.StopRecording();
numberRecords += 1;
}





share|improve this answer


























  • Errors remained

    – John Berden
    Nov 24 '18 at 14:59











  • I updated my answer to be more clear. Do you get the same error messages? If they are different now, please post the new ones (better edit your question for this than adding another comment, also better add the error messages as text, not as picture).

    – Klaus Gütter
    Nov 24 '18 at 15:32











  • Error CS0029 Cannot implicitly convert type 'System.EventHandler' to 'System.EventHandler<NAudio.Wave.StoppedEventArgs>' RecordBooks

    – John Berden
    Nov 24 '18 at 18:12











  • The error message also includes a line number; and double-clicking on the error message will get you to the offending line in the visual studio code editor. Probably it is this one: waveIn.RecordingStopped += new EventHandler(waveIn_RecordingStopped);; change it to waveIn.RecordingStopped += waveIn_RecordingStopped; and alco correct the method signature of waveIn_RecordingStopped to void waveIn_RecordingStopped(object sender, StoppedEventArgs e)

    – Klaus Gütter
    Nov 25 '18 at 6:45













  • CS0123 No overload for 'waveIn_RecordingStopped' matches delegate 'EventHandler' RecordBooks Line 86

    – John Berden
    Nov 26 '18 at 12:46
















0














You did not close the method StartRecording() with a }. Therefore all following methods are local to StartRecording and not visible outside.



void StartRecording()
{
try
{
waveIn = new WaveIn();
waveIn.DeviceNumber = 0;
waveIn.DataAvailable += waveIn_DataAvailable;
waveIn.RecordingStopped += new EventHandler(waveIn_RecordingStopped);
waveIn.WaveFormat = new WaveFormat(8000, 1);
recordFile = numberRecords + ".wav";
writer = new WaveFileWriter(recordFile);
waveIn.StartRecording();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
} // <<<-- this was missing

void StopRecording()
{
waveIn.StopRecording();
numberRecords += 1;
}





share|improve this answer


























  • Errors remained

    – John Berden
    Nov 24 '18 at 14:59











  • I updated my answer to be more clear. Do you get the same error messages? If they are different now, please post the new ones (better edit your question for this than adding another comment, also better add the error messages as text, not as picture).

    – Klaus Gütter
    Nov 24 '18 at 15:32











  • Error CS0029 Cannot implicitly convert type 'System.EventHandler' to 'System.EventHandler<NAudio.Wave.StoppedEventArgs>' RecordBooks

    – John Berden
    Nov 24 '18 at 18:12











  • The error message also includes a line number; and double-clicking on the error message will get you to the offending line in the visual studio code editor. Probably it is this one: waveIn.RecordingStopped += new EventHandler(waveIn_RecordingStopped);; change it to waveIn.RecordingStopped += waveIn_RecordingStopped; and alco correct the method signature of waveIn_RecordingStopped to void waveIn_RecordingStopped(object sender, StoppedEventArgs e)

    – Klaus Gütter
    Nov 25 '18 at 6:45













  • CS0123 No overload for 'waveIn_RecordingStopped' matches delegate 'EventHandler' RecordBooks Line 86

    – John Berden
    Nov 26 '18 at 12:46














0












0








0







You did not close the method StartRecording() with a }. Therefore all following methods are local to StartRecording and not visible outside.



void StartRecording()
{
try
{
waveIn = new WaveIn();
waveIn.DeviceNumber = 0;
waveIn.DataAvailable += waveIn_DataAvailable;
waveIn.RecordingStopped += new EventHandler(waveIn_RecordingStopped);
waveIn.WaveFormat = new WaveFormat(8000, 1);
recordFile = numberRecords + ".wav";
writer = new WaveFileWriter(recordFile);
waveIn.StartRecording();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
} // <<<-- this was missing

void StopRecording()
{
waveIn.StopRecording();
numberRecords += 1;
}





share|improve this answer















You did not close the method StartRecording() with a }. Therefore all following methods are local to StartRecording and not visible outside.



void StartRecording()
{
try
{
waveIn = new WaveIn();
waveIn.DeviceNumber = 0;
waveIn.DataAvailable += waveIn_DataAvailable;
waveIn.RecordingStopped += new EventHandler(waveIn_RecordingStopped);
waveIn.WaveFormat = new WaveFormat(8000, 1);
recordFile = numberRecords + ".wav";
writer = new WaveFileWriter(recordFile);
waveIn.StartRecording();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
} // <<<-- this was missing

void StopRecording()
{
waveIn.StopRecording();
numberRecords += 1;
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 24 '18 at 15:30

























answered Nov 24 '18 at 14:29









Klaus GütterKlaus Gütter

2,51821321




2,51821321













  • Errors remained

    – John Berden
    Nov 24 '18 at 14:59











  • I updated my answer to be more clear. Do you get the same error messages? If they are different now, please post the new ones (better edit your question for this than adding another comment, also better add the error messages as text, not as picture).

    – Klaus Gütter
    Nov 24 '18 at 15:32











  • Error CS0029 Cannot implicitly convert type 'System.EventHandler' to 'System.EventHandler<NAudio.Wave.StoppedEventArgs>' RecordBooks

    – John Berden
    Nov 24 '18 at 18:12











  • The error message also includes a line number; and double-clicking on the error message will get you to the offending line in the visual studio code editor. Probably it is this one: waveIn.RecordingStopped += new EventHandler(waveIn_RecordingStopped);; change it to waveIn.RecordingStopped += waveIn_RecordingStopped; and alco correct the method signature of waveIn_RecordingStopped to void waveIn_RecordingStopped(object sender, StoppedEventArgs e)

    – Klaus Gütter
    Nov 25 '18 at 6:45













  • CS0123 No overload for 'waveIn_RecordingStopped' matches delegate 'EventHandler' RecordBooks Line 86

    – John Berden
    Nov 26 '18 at 12:46



















  • Errors remained

    – John Berden
    Nov 24 '18 at 14:59











  • I updated my answer to be more clear. Do you get the same error messages? If they are different now, please post the new ones (better edit your question for this than adding another comment, also better add the error messages as text, not as picture).

    – Klaus Gütter
    Nov 24 '18 at 15:32











  • Error CS0029 Cannot implicitly convert type 'System.EventHandler' to 'System.EventHandler<NAudio.Wave.StoppedEventArgs>' RecordBooks

    – John Berden
    Nov 24 '18 at 18:12











  • The error message also includes a line number; and double-clicking on the error message will get you to the offending line in the visual studio code editor. Probably it is this one: waveIn.RecordingStopped += new EventHandler(waveIn_RecordingStopped);; change it to waveIn.RecordingStopped += waveIn_RecordingStopped; and alco correct the method signature of waveIn_RecordingStopped to void waveIn_RecordingStopped(object sender, StoppedEventArgs e)

    – Klaus Gütter
    Nov 25 '18 at 6:45













  • CS0123 No overload for 'waveIn_RecordingStopped' matches delegate 'EventHandler' RecordBooks Line 86

    – John Berden
    Nov 26 '18 at 12:46

















Errors remained

– John Berden
Nov 24 '18 at 14:59





Errors remained

– John Berden
Nov 24 '18 at 14:59













I updated my answer to be more clear. Do you get the same error messages? If they are different now, please post the new ones (better edit your question for this than adding another comment, also better add the error messages as text, not as picture).

– Klaus Gütter
Nov 24 '18 at 15:32





I updated my answer to be more clear. Do you get the same error messages? If they are different now, please post the new ones (better edit your question for this than adding another comment, also better add the error messages as text, not as picture).

– Klaus Gütter
Nov 24 '18 at 15:32













Error CS0029 Cannot implicitly convert type 'System.EventHandler' to 'System.EventHandler<NAudio.Wave.StoppedEventArgs>' RecordBooks

– John Berden
Nov 24 '18 at 18:12





Error CS0029 Cannot implicitly convert type 'System.EventHandler' to 'System.EventHandler<NAudio.Wave.StoppedEventArgs>' RecordBooks

– John Berden
Nov 24 '18 at 18:12













The error message also includes a line number; and double-clicking on the error message will get you to the offending line in the visual studio code editor. Probably it is this one: waveIn.RecordingStopped += new EventHandler(waveIn_RecordingStopped);; change it to waveIn.RecordingStopped += waveIn_RecordingStopped; and alco correct the method signature of waveIn_RecordingStopped to void waveIn_RecordingStopped(object sender, StoppedEventArgs e)

– Klaus Gütter
Nov 25 '18 at 6:45







The error message also includes a line number; and double-clicking on the error message will get you to the offending line in the visual studio code editor. Probably it is this one: waveIn.RecordingStopped += new EventHandler(waveIn_RecordingStopped);; change it to waveIn.RecordingStopped += waveIn_RecordingStopped; and alco correct the method signature of waveIn_RecordingStopped to void waveIn_RecordingStopped(object sender, StoppedEventArgs e)

– Klaus Gütter
Nov 25 '18 at 6:45















CS0123 No overload for 'waveIn_RecordingStopped' matches delegate 'EventHandler' RecordBooks Line 86

– John Berden
Nov 26 '18 at 12:46





CS0123 No overload for 'waveIn_RecordingStopped' matches delegate 'EventHandler' RecordBooks Line 86

– John Berden
Nov 26 '18 at 12:46




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53458516%2fwhat-are-the-errors-in-my-code-with-naudio%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

Refactoring coordinates for Minecraft Pi buildings written in Python