Live Audio Streaming

Hi all.
I want to sample 8000 times/sec analog input of a microphone (A0). After taking each sample, I want to output it to a speaker attached to pin 10 and a simple amplifier circuit I created.
I know that I should use a timer interrupt function and this is what I've written.

void setup() {
  // 
  cli();
  
  // 
  TCCR2A = 0;
  TCCR2B = 0;
  TCNT2 = 0;
  OCR2A = 249;
  TCCR2A |= (1 << WGM21);
  TCCR2B |= (1 << CS21);
  TIMSK2 |= (1 << OCIE2A);
  
  // 
  sei();

}

ISR(TIMER2_COMPA_vect) {
  // 
  analogWrite(10, map(analogRead(0), 0, 1023, 0, 255);
}

void loop() {
  
}

After uploading this code, the speaker is making a continuous beep an when I make noise and the microphone catch it and the speaker is distorted.
I want to make a live audio processor and my first target was to output the audio input as is.

The Arduino doesn't have a true digital-to-analog converter. It uses PWM which is good for dimming an LED or controling a DC moter, and you can make tones and get some other sounds out of it, but I wouldn't use it for what you are trying to do.

The easiest thing would be to use an Audio Shield designed for the Arduino.

...analog input of a microphone (A0).

You aren't connecting a microphone directly, are you? You need a preamp, because you only get a few millivolts out of a mic (depending on the loudness of the sound and the sensitivity of the mic), and since the Arduino cannot accept the negative half of the waveform, the signal needs to be biased at 2.5V (which means the ADC will read read about 512 with silence).

I know people have made guitar effects boxes with the Arduino, but I assume they are using an additional DAC or audio shield.

I want to sample 8000 times/sec...

At a sample-rate of 8kHz, your audio will be limited to 4kHz (Nyquist sampling theory). You generally need to low-pass filter your audio before feeding it into the ADC, because if there is anything above 4kHz you'll get aliasing (false frequencies).

DVDdoug:
The Arduino doesn't have a true digital-to-analog converter. It uses PWM which is good for dimming an LED or controling a DC moter, and you can make tones and get some other sounds out of it, but I wouldn't use it for what you are trying to do.

There's nothing inherently wrong with using PWM to create tones in a speaker, it's the entire basis of class D amplifiers after all.

The practical problem is that the Arduino's analogWrite() function doesn't have that high of a frequency. I think it's only about 500 Hz, which, as DVDdoug says, is good enough for a motor or LED, useless for audio.

Even if you manually set the timer yourself, the maximum PWM frequency you can get from an Arduino @ 16 MHz is 62.5 kHz. Most class D amps work at well over 100 kHz (my TPA3122 PWMs at 250 kHz).

The other problem is that the power supply rejection ratio (PSRR) of your setup is going to be very poor without a feedback network. Any power supply fluctuation will cause fluctuations in the volume of your output.

What type of audio processing do you have in mind? This stuff is probably better done on a DSP than an Arduino, or done on hardware.