Update tools/cmd/infer_cli.py
Browse files- tools/cmd/infer_cli.py +31 -0
tools/cmd/infer_cli.py
CHANGED
|
@@ -1,6 +1,10 @@
|
|
| 1 |
import argparse
|
| 2 |
import os
|
| 3 |
import sys
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
now_dir = os.getcwd()
|
| 6 |
sys.path.append(now_dir)
|
|
@@ -63,5 +67,32 @@ def main():
|
|
| 63 |
wavfile.write(args.opt_path, wav_opt[0], wav_opt[1])
|
| 64 |
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
if __name__ == "__main__":
|
| 67 |
main()
|
|
|
|
| 1 |
import argparse
|
| 2 |
import os
|
| 3 |
import sys
|
| 4 |
+
from pydub import AudioSegment
|
| 5 |
+
import matplotlib.pyplot as plt
|
| 6 |
+
import numpy as np
|
| 7 |
+
|
| 8 |
|
| 9 |
now_dir = os.getcwd()
|
| 10 |
sys.path.append(now_dir)
|
|
|
|
| 67 |
wavfile.write(args.opt_path, wav_opt[0], wav_opt[1])
|
| 68 |
|
| 69 |
|
| 70 |
+
|
| 71 |
+
# Load the audio file
|
| 72 |
+
audio = AudioSegment.from_file(wav_opt) # Replace with your audio file path
|
| 73 |
+
|
| 74 |
+
# Display basic information about the audio file
|
| 75 |
+
print(f"Channels: {audio.channels}")
|
| 76 |
+
print(f"Sample Width: {audio.sample_width} bytes")
|
| 77 |
+
print(f"Frame Rate (Sample Rate): {audio.frame_rate} Hz")
|
| 78 |
+
print(f"Frame Width: {audio.frame_width} bytes")
|
| 79 |
+
print(f"Length: {len(audio)} ms")
|
| 80 |
+
|
| 81 |
+
# Convert the audio data to a numpy array for visualization
|
| 82 |
+
samples = np.array(audio.get_array_of_samples())
|
| 83 |
+
|
| 84 |
+
# If the audio has more than one channel, split the samples into multiple arrays
|
| 85 |
+
if audio.channels == 2:
|
| 86 |
+
samples = samples.reshape((-1, 2))
|
| 87 |
+
|
| 88 |
+
# Plot the waveform
|
| 89 |
+
plt.figure(figsize=(15, 5))
|
| 90 |
+
plt.plot(samples[:1000]) # Plotting first 1000 samples for clarity
|
| 91 |
+
plt.title("Waveform of the Audio File")
|
| 92 |
+
plt.xlabel("Sample")
|
| 93 |
+
plt.ylabel("Amplitude")
|
| 94 |
+
plt.show()
|
| 95 |
+
|
| 96 |
+
|
| 97 |
if __name__ == "__main__":
|
| 98 |
main()
|