Sampling the audio from the microphone and sending it to the computer via the serial port

What I want to do is to sample the sound coming from the microphone and process it in the software I wrote on the computer via the serial port. I don't have any piece of code at hand and I don't quite understand where to start.
I just want to sample sound from microphone with arduino uno and transmit to serial port.
I have an idea how the data package and software on the computer will be, but I don't know how to handle the sound on the arduino.
I'm new to audio.
Thanks in advance.

Welcome to the Arduino forum. This is quite a complex design for the first time project. Have you worked through many of the sample programs that come with the Arduino IDE?

Next, identify the type of microphone you have there, we can't see it.

You will need an amplifier between the microphone and your Arduino.

In the meantime, start with any of the sample programs that use the analog/digital pin to read a voltage and get that working. Your sound program will be very similar.

I'm actually going to use an electret microphone for the first phase of the project. I have an amplifier but I don't know what standards it should be. If I succeed, I will sample the sound from an rf receiver and transfer it to the computer. I'm also planning this to be real time. I forgot to say this.

Since audio is AC, the output of your amplifier has to be limited to 1/2 of the voltage you are using to power your Arduino.
I certainly hope your expectations for any quality audio are not very high. Just getting ANY sound from your PC will be mainly luck.
There are many threads on the forum relating to audio. Have you searched through the audio part for similar projects?

I don't have high expectations for sound quality, I will use higher quality hardware and different software in a future project, so I wanted to start with arduino because I only have arduino.

I searched the forum a bit, often came across projects with different purposes. I did not expect the same points to be found in the subject I was researching, but I felt the need to open a new topic because I thought there were important details.

Don't expect someone else to have the same project as you do. BUT find a thread that just reads the signal from a microphone, that is where your project begins and then add other steps to it.

I don't expect anyone to have the same project as me anyway. I think this way too, but I couldn't find a topic in the forum where I can read the signal coming from the microphone.

I searched on "microphone" and got hits.

watch this video until the end, it uploads the code 2 times, in the first one in the form of waw to the serial port, in the second, when you copy the text on the serial port and paste it on the wi-fi link, the download link comes and the audio recording is listened to there.

Did you mention which Arduino you have?

Here is a schematic for a microphone preamp with power for the electret and the required biased-output. Or, it's cheap so you might just want to buy it. (This particular preamp doesn't have a gain control.)

The "regular Arduino" is a little too-slow for high quality audio and the ADC is only 10-bits. And the serial transmission is going to eat-up some processor cycles. Plus whatever "processing' you want to do. So... You might end-up being limited to low frequencies or you may be limited to short-bits of audio and unable to transmit continuously.

If you don't know anything about digital audio the Audacity website has a nice gentle introduction.

You also need to know about aliasing and the Nyquist limit - If the sample rate is less than twice the signal frequency (at least one sample for the positive half of the waveform and one for the bottom half) you'll get "false frequencies". That means you need an analog low-pass "anti aliasing" filter before the signal is digitized.

Sometimes, if you don't care about quality you can get-by without an anti-aliasing filter because the highest audio frequencies tend to be weak and that makes the aliases weak. But it's standard on an audio ADC and every soundcard has an anti-aliasing filter.

Technically, that would probably be easier than a microphone interface if the radio has a headphone plug for example. A simple voltage divider with limiter would do it.

Sorry for the late reply, I had to take a break for a few days due to health issues.

Did you mention which Arduino you have?

Yes, i have Arduino Uno

Technically, that would probably be easier than a microphone interface if the radio has a headphone plug for example. A simple voltage divider with limiter would do it.

It would be really practical, thanks for the idea.

You need to bias the signal because the Arduino can be damaged by negative voltages and/or the audio signal can be "damaged" (distorted).

Audio Input Schematic

With the bias circuit silence read about 512 on the and the audio will ride on top of that 512 bias, which can be subtracted-out in software.

With a speaker connection you may need another voltage divider for the audio and/or an over-voltage protection circuit.

Just to get started you can run the Analog Read Serial Example. Take-out the delay.

Of course the readings will "look random" because you are sampling a waveform, and they will look random even with a constant tone. But you should be able to see if you are getting "usable" numbers and you should see a difference between loud and quiet (or silent) audio.

I made my calculations according to the information you gave, I sample at certain periods and transfer the chunk to the serial port, but when I convert this 8-bit data back to sound in python or another language, a meaningless sound comes out. Is there a sound library you can recommend?

How fast was your serial port operating?

By now, you should realize that we need hard numbers and facts.

I'm not sure but I doubt the Uno is fast enough to do what you're trying to. You probably need to count the samples for a known period of time to see if you are running at the sample rate you think you're running at. You might have to count the samples captured by the Arduino (over a one second period), and then again count the samples received by the computer...

Computers process audio that way but they are faster, have dedicated hardware, and more memory... And computers have to handle that way because the multitasking operating system prevents continuous processing... When you record, the digital audio is sampled and written to a buffer (memory} continuously at a smooth-constant rate. (This is independent of the CPU and operating system.) When the operating system gets-around to it, the buffer is read in a quick burst and written to the hard drive.

When you play back, the buffer works the opposite way. The buffer is filled in a quick burst and the audio data comes-out at a smooth-constant rate.

The Uno has 2KB of RAM so if we assume a (slow) sample rate of 8kHz and 8-bit audio, and assuming the RAM is used for almost nothing else, that's 1/4 second of audio.

Did you convert the 10-bit ADC data to 8-bits? This is a little tricky with the bias. Otherwise you can save and transmit the 16-bit data and Python can do the conversion. When you read the ADC, the bits end-up as a 16-bit integer (with the 6 most significant bits zeros), Keeping the 16-bit data is a trade-off because it's twice as much data but it means less processing by the Arduino.

Of course, Python needs to know the sample rate and the bit depth.

But, I'd guess your audio is "scrambled" because you are missing chunks of data when you stop sampling to transmit. And/or your sample rate may be a lot lower than you think because the Arduino can't process fast-enough.

P.S.
Since you've got a computer, presumably with a soundcard, you probably don't need the Arduino,