-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_wav.py
More file actions
35 lines (28 loc) · 801 Bytes
/
plot_wav.py
File metadata and controls
35 lines (28 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import numpy as np
import matplotlib.pyplot as plt
from scipy.io.wavfile import read
import sys
import os
mic_path = "wav_folder/signal_0.wav"
if len(sys.argv) > 1:
file_path = sys.argv[1]
else:
print("Usage: python test.py <file_path>")
sys.exit(1)
if not file_path.lower().endswith('.wav'):
print("Error: The file must be a .wav file.")
sys.exit(1)
if not os.path.exists(file_path):
print(f"Error: The file '{file_path}' does not exist.")
sys.exit(1)
sample_rate, data = read(file_path)
if data.ndim > 1:
data = data.mean(axis=1)
time = np.linspace(0, len(data) / sample_rate, num=len(data))
plt.figure(figsize=(10, 6))
plt.plot(time, data)
plt.title(f"Audio Signal of '{file_path}'")
plt.xlabel("Time (seconds)")
plt.ylabel("Amplitude")
plt.grid()
plt.show()