diff --git a/downsample.py b/downsample.py new file mode 100644 index 0000000..47d1ba8 --- /dev/null +++ b/downsample.py @@ -0,0 +1,8 @@ +import librosa +import soundfile as sf + +y, sr = librosa.load('aeiou-espeak.wav', sr=22000) +sf.write('downsample1.wav', y, sr) + +y, sr = librosa.load('aeiou-espeak.wav', sr=11000) +sf.write('downsample2.wav', y, sr) diff --git a/invert-phase.py b/invert-phase.py new file mode 100644 index 0000000..22eb9c0 --- /dev/null +++ b/invert-phase.py @@ -0,0 +1,15 @@ +from pydub import AudioSegment +from pydub.playback import play + +my_audio_file = "sine-50.wav" + +sound1 = AudioSegment.from_file(my_audio_file, format="wav") + +sound2 = sound1.invert_phase() +sound2.export("wav/invert-phase.wav", format="wav") + +combined = sound1.overlay(sound2) +combined.export("wav/output-mix-invert-phase.wav", format="wav") + +merged_audio = AudioSegment.from_wav("wav/output-mix-invert-phase.wav") +play(merged_audio) diff --git a/mix-audio.py b/mix-audio.py new file mode 100644 index 0000000..c38e224 --- /dev/null +++ b/mix-audio.py @@ -0,0 +1,9 @@ +from pydub import AudioSegment + +my_audio_file = "wav/sine-300.wav" + +sound1 = AudioSegment.from_file(my_audio_file, format="wav") +sound2 = AudioSegment.from_file(my_audio_file.replace('300', '305'), format="wav") + +combined = sound1.overlay(sound2) +combined.export("wav/mixed-300-305.wav", format="wav") diff --git a/spectrogram.py b/spectrogram.py new file mode 100644 index 0000000..e4ebff6 --- /dev/null +++ b/spectrogram.py @@ -0,0 +1,26 @@ +import matplotlib.pyplot as plot +from scipy.io import wavfile +import argparse + +def main() -> None: + parser = argparse.ArgumentParser() + parser.add_argument("-i", "--input", type=str, required=True) + args = parser.parse_args() + + sampling_frequency, signal_data = wavfile.read(args.input) + + plot.subplot(211) + plot.title('Waveform and spectrogram view') + + plot.plot(signal_data) + plot.xlabel('Sample') + plot.ylabel('Amplitude') + + plot.subplot(212) + plot.specgram(signal_data, Fs=sampling_frequency) + plot.xlabel('Time') + plot.ylabel('Frequency') + plot.show() + +if __name__ == "__main__": + main() diff --git a/white-noise.py b/white-noise.py new file mode 100644 index 0000000..bac144b --- /dev/null +++ b/white-noise.py @@ -0,0 +1,9 @@ +from scipy.io import wavfile +import numpy + +mean = 0 +std = 1 +num_samples = 100000 +samples = numpy.random.normal(mean, std, size=num_samples) + +wavfile.write("white-noise.wav", 44100, samples)