How to add echo to .wav file in python ??

Joined
Jan 12, 2023
Messages
2
Reaction score
0
import pyaudio
import wave
import matplotlib.pyplot as plt
import numpy as np
import winsound

FRAMES_PER_BUFFER = 3200
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 16000

pa = pyaudio.PyAudio()

stream = pa.open(
format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=FRAMES_PER_BUFFER
)

obj = wave.open('My_RecordedAudio_file.wav', 'wb')
obj.setnchannels(CHANNELS)
obj.setsampwidth(pa.get_sample_size(FORMAT))
obj.setframerate(RATE)
obj.writeframes(b''.join(frames))
obj.close()

frames1 = frames
file = wave.open('My_RecordedAudio_file.wav', 'rb')
sample_freq = file.getframerate()
frames = file.getnframes()
signal_wave = file.readframes(-1)
file.close()

winsound.PlaySound('My_RecordedAudio_file.wav', winsound.SND_FILENAME)

How may i add echo to My_RecordedAudio_file.wav ????
Yours help regarding this will be pleaure .
 
Joined
Jan 8, 2023
Messages
27
Reaction score
2
You can add echo to a .wav file by applying an echo effect to the audio data using a library such as scipy or pydub. Here's an example using pydub:


Python:
from pydub import AudioSegment

# Load audio file
audio = AudioSegment.from_wav("My_RecordedAudio_file.wav")

# Add echo
echoed_audio = audio.apply_effect(echo=0.1, n=3)

# Save the echoed audio
echoed_audio.export("My_RecordedAudio_file_echoed.wav", format="wav")
 
Joined
Jan 12, 2023
Messages
2
Reaction score
0
You can add echo to a .wav file by applying an echo effect to the audio data using a library such as scipy or pydub. Here's an example using pydub:


Python:
from pydub import AudioSegment

# Load audio file
audio = AudioSegment.from_wav("My_RecordedAudio_file.wav")

# Add echo
echoed_audio = audio.apply_effect(echo=0.1, n=3)

# Save the echoed audio
echoed_audio.export("My_RecordedAudio_file_echoed.wav", format="wav")
it give this errror in myside ...

AttributeError: 'AudioSegment' object has no attribute 'apply_effect'.
 
Joined
Jan 30, 2023
Messages
107
Reaction score
13
To add echo to an audio file, you can apply a delay effect to the signal. Here is an example of how to add an echo to the audio signal in python using the numpy library

Python:
import numpy as np

# Load the audio signal
signal = np.frombuffer(signal_wave, dtype=np.int16)

# Define the echo parameters
echo_gain = 0.5
echo_delay = 0.5

# Create the echoed
echo = np.zeros(len(signal) + int(echo_delay * sample_freq))
echo[:len(signal)] = signal * echo_gain

# Apply the echoes
output = signal + echo[:len(signal)]

# Convert the signal back to the original format
output = output.astype(np.int16)

# Save the output to a new audio file
with wave.open("My_RecordedAudio_file_with_echo.wav", "wb") as out_file:
    out_file.setnchannels(CHANNELS)
    out_file.setsampwidth(pa.get_sample_size(FORMAT))
    out_file.setframerate(RATE)
    out_file.writeframes(output.tobytes())

This code creates an echo by creating a new signal with zeros, adding the original signal multiplied by the echo gain to the new signal, and adding the new signal to the original signal to create the output. The output is then saved to a new audio file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top