Skip to content

Commit ddf9ee4

Browse files
Merge pull request #8 from AdityaSeth777/v4.0-pyqt5
Total enhancement - v4.0 Details : ## Things added and improvements : ### - Added PyQt5 modules and a Gaussian filter that enables user input for Duration (in seconds), Sampling Rate (in Hz), Block Size, and also smoothens the output. ### - Launched on Product Hunt and added the links in Readme. ### - Updated the License. --- ## Notable points : ### From v4.0, I have implemented a whole new code using PyQt5, which you will find evident here in the new main default code - ['main-old.py'](https://github.com/AdityaSeth777/Audio-SpectraCLI/blob/4.0/Audio_SpectraCLI/main.py) and the ['test-old.py'](https://github.com/AdityaSeth777/Audio-SpectraCLI/blob/4.0/tests/test.py) case supporting that. ### The ['main-old.py'](https://github.com/AdityaSeth777/Audio-SpectraCLI/blob/4.0/Audio_SpectraCLI/main-old.py), which is the code for the main file for v3.2, and the ['test-old.py'](https://github.com/AdityaSeth777/Audio-SpectraCLI/blob/4.0/tests/test.py) case supporting that, is DEPRECATED.
2 parents d7653dd + 2938617 commit ddf9ee4

File tree

17 files changed

+770
-125
lines changed

17 files changed

+770
-125
lines changed

Audio_SpectraCLI.egg-info/PKG-INFO

Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
Metadata-Version: 2.1
2+
Name: Audio_SpectraCLI
3+
Version: 4.0
4+
Summary: AudioSpectraCLI is a tool that provides real-time FFT visualization of audio spectra. It captures audio input from the microphone and displays the corresponding frequency spectrum directly, allowing users to monitor and analyze audio signals.
5+
Home-page: https://github.com/AdityaSeth777/Audio-SpectraCLI
6+
Author: Aditya Seth
7+
Author-email: contact@adityaseth.in
8+
License: Apache License 2.0
9+
Description-Content-Type: text/markdown
10+
License-File: LICENSE
11+
Requires-Dist: numpy
12+
Requires-Dist: matplotlib
13+
Requires-Dist: sounddevice
14+
Requires-Dist: tabulate
15+
Requires-Dist: setuptools
16+
Requires-Dist: twine
17+
Requires-Dist: wheel
18+
Requires-Dist: pyqt5
19+
Requires-Dist: pyaudio
20+
21+
```
22+
_ _ _ ____ _ ____ _ ___
23+
/ \ _ _ __| (_) ___ / ___| _ __ ___ ___| |_ _ __ __ _ / ___| | |_ _|
24+
/ _ \| | | |/ _` | |/ _ \ ____\___ \| '_ \ / _ \/ __| __| '__/ _` | | | | | |
25+
/ ___ \ |_| | (_| | | (_) |_____|__) | |_) | __/ (__| |_| | | (_| | |___| |___ | |
26+
/_/ \_\__,_|\__,_|_|\___/ |____/| .__/ \___|\___|\__|_| \__,_|\____|_____|___|
27+
|_|
28+
```
29+
30+
## Audio Spectrum Visualization is a Python project that visualizes real-time audio input as a spectrum using Fast Fourier Transform (FFT). It provides an interactive and dynamic interface for users to start the visualization and exit the program.
31+
32+
<p>
33+
34+
![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat)
35+
[![Visitors](https://api.visitorbadge.io/api/visitors?path=https%3A%2F%2Fgithub.com%2FAdityaSeth777%2FAudio-SpectraCLI&label=Visitors&countColor=%23263759&style=plastic)](https://visitorbadge.io/status?path=https%3A%2F%2Fgithub.com%2FAdityaSeth777%2FAudio-SpectraCLI)
36+
![GitHub forks](https://img.shields.io/github/forks/AdityaSeth777/Audio-SpectraCLI)
37+
![GitHub Repo stars](https://img.shields.io/github/stars/AdityaSeth777/Audio-SpectraCLI)
38+
![GitHub last commit](https://img.shields.io/github/last-commit/AdityaSeth777/Audio-SpectraCLI)
39+
![GitHub repo size](https://img.shields.io/github/repo-size/AdityaSeth777/Audio-SpectraCLI)
40+
![GitHub issues](https://img.shields.io/github/issues/AdityaSeth777/Audio-SpectraCLI)
41+
![GitHub closed issues](https://img.shields.io/github/issues-closed-raw/AdityaSeth777/Audio-SpectraCLI)
42+
![GitHub pull requests](https://img.shields.io/github/issues-pr/AdityaSeth777/Audio-SpectraCLI)
43+
![GitHub closed pull requests](https://img.shields.io/github/issues-pr-closed/AdityaSeth777/Audio-SpectraCLI)
44+
45+
</p>
46+
47+
<a href="https://www.producthunt.com/posts/audio-spectracli?utm_source=badge-featured&utm_medium=badge&utm_souce=badge-audio&#0045;spectracli" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=458166&theme=light" alt="Audio&#0045;SpectraCLI - Visualizing&#0032;real&#0045;time&#0032;audio&#0032;input&#0032;as&#0032;a&#0032;spectrum&#0032;using&#0032;FFT | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a>
48+
49+
### Notable point : From v4.0, I have implemented a whole new code using PyQt5, which you will find evident here in the new main default code - [&#39;main.py&#39;](./Audio_SpectraCLI/main.py) and the [&#39;test.py&#39;](./tests/test.py) case supporting that.
50+
51+
### The [&#39;main-old.py&#39;](./Audio_SpectraCLI/main-old.py), which is the code for the main file for v3.2, and the [&#39;test-old.py&#39;](./tests/test-old.py) case supporting that, is DEPRECATED.
52+
53+
## Current Features (with respect to 4.0)
54+
55+
- Real-time visualization of Fast Fourier Transform (FFT) spectrum of audio input.
56+
- Support for adjusting parameters such as duration, sampling rate, and block size.
57+
- Seamless integration with SoundDevice for audio input capture.
58+
- Customizable Frequency Range: Allow users to specify the frequency range to display in the spectrum.
59+
- Color Customization: Provide options for users to customize the colors used in the spectrum visualization.
60+
- Added PyQt5 modules that enables user input for Duration (in seconds), Sampling Rate (in Hz), and Block Size.
61+
- Much more dynamic and user-controlled interface.
62+
63+
## Packaging
64+
65+
```
66+
Audio-SpectraCLI/
67+
68+
├── .gitignore
69+
├── CODE_OF_CONDUCT.md
70+
├── Contributing.md
71+
├── Dockerfile
72+
├── LICENSE
73+
├── Readme.md
74+
├── requirements.txt
75+
├── setup.cfg
76+
├── setup.py
77+
├── .github/
78+
│ └── workflows/
79+
│ ├── docker-publish.yml
80+
│ ├── label.yml
81+
│ └── python-publish.yml
82+
├── Audio_SpectraCLI/
83+
│ ├── main-old.py
84+
│ ├── main.py
85+
│ └── __init__.py
86+
└── tests/
87+
├── test-old.py
88+
└── test.py
89+
```
90+
91+
## Installation & Usage (Using PIP)
92+
93+
1. Install using pip
94+
95+
```
96+
pip install Audio-SpectraCLI
97+
```
98+
99+
2. Import and use modules
100+
101+
- Create a Python file.
102+
- You can use [Example.py](https://github.com/AdityaSeth777/Audio-SpectraCLI/blob/main/tests/test.py) as a reference or use the following code :
103+
104+
```python
105+
from Audio_SpectraCLI import AudioSpectrumVisualizer
106+
from PyQt5.QtWidgets import QApplication
107+
108+
# Creating an instance of AudioSpectrumVisualizer with custom parameters
109+
app = QApplication([])
110+
audio_visualizer = AudioSpectrumVisualizer(
111+
duration=10, fs=22050, block_size=8192, frequency_range=(2000, 5000), color='green')
112+
113+
# Starting the audio spectrum visualization
114+
audio_visualizer.show()
115+
audio_visualizer.start_visualization()
116+
app.exec_()
117+
```
118+
119+
Once you have activated the audio_visualizer instance, feel free to use it wherever in the program. It consists of several parameters (which gives more control to the user), so make sure to configure and add those before using it in your code. Also, the user can modify (wrt [v4.0](https://github.com/AdityaSeth777/Audio-SpectraCLI/tree/4.0)) the Duration (in seconds), Sampling Rate (in Hz), and Block Size.
120+
121+
---
122+
123+
## Examining & Usage for fun :D (Using Docker)
124+
125+
1. Prerequisites
126+
You should have docker installed on your machine. You can download and install Docker from [here](https://www.docker.com/products/docker-desktop).
127+
2. Pulling the Docker Image
128+
129+
You can pull the pre-built Docker image from Docker Hub using the following command:
130+
131+
```sh
132+
docker pull adityaseth777/audio-spectracli
133+
```
134+
135+
3. Viewing Files Inside the Docker Container
136+
For seeing the files inside the Docker container for debugging purposes, you can run an interactive shell session:
137+
138+
```sh
139+
docker run --rm -it --entrypoint /bin/bash audio-spectracli
140+
```
141+
142+
4. Use the 'ls' command to view the files and get a proper understanding of the file structure :
143+
144+
```sh
145+
ls
146+
```
147+
148+
5. You can use [Example.py](https://github.com/AdityaSeth777/Audio-SpectraCLI/blob/main/tests/test.py) as a reference or use the following code :
149+
150+
```python
151+
from Audio_SpectraCLI import AudioSpectrumVisualizer
152+
from PyQt5.QtWidgets import QApplication
153+
154+
# Creating an instance of AudioSpectrumVisualizer with custom parameters
155+
app = QApplication([])
156+
audio_visualizer = AudioSpectrumVisualizer(
157+
duration=10, fs=22050, block_size=8192, frequency_range=(2000, 5000), color='green')
158+
159+
# Starting the audio spectrum visualization
160+
audio_visualizer.show()
161+
audio_visualizer.start_visualization()
162+
app.exec_()
163+
```
164+
165+
Once you have activated the audio_visualizer instance, feel free to use it wherever in the program. It consists of several parameters (which gives more control to the user), so make sure to configure and add those before using it in your code. Also, the user can modify (wrt [v4.0](https://github.com/AdityaSeth777/Audio-SpectraCLI/tree/4.0)) the Duration (in seconds), Sampling Rate (in Hz), and Block Size.
166+
167+
---
168+
169+
## Building the Docker Image Locally (for fun :D)
170+
171+
If you prefer to build the Docker image locally, follow these steps:
172+
173+
1. Clone the repository :
174+
175+
```sh
176+
git clone https://github.com/AdityaSeth777/Audio-SpectraCLI.git
177+
cd Audio-SpectraCLI
178+
```
179+
180+
2. Build the Docker image:
181+
182+
```sh
183+
docker build -t audio-spectracli .
184+
```
185+
186+
3. Viewing Files Inside the Docker Container
187+
For seeing the files inside the Docker container for debugging purposes, you can run an interactive shell session:
188+
189+
```sh
190+
docker run --rm -it --entrypoint /bin/bash audio-spectracli
191+
```
192+
193+
4. Use the 'ls' command to view the files and get a proper understanding of the file structure :
194+
195+
```sh
196+
ls
197+
```
198+
199+
5. You can use [Example.py](https://github.com/AdityaSeth777/Audio-SpectraCLI/blob/main/tests/test.py) as a reference or use the following code :
200+
201+
```python
202+
from Audio_SpectraCLI import AudioSpectrumVisualizer
203+
from PyQt5.QtWidgets import QApplication
204+
205+
# Creating an instance of AudioSpectrumVisualizer with custom parameters
206+
app = QApplication([])
207+
audio_visualizer = AudioSpectrumVisualizer(
208+
duration=10, fs=22050, block_size=8192, frequency_range=(2000, 5000), color='green')
209+
210+
# Starting the audio spectrum visualization
211+
audio_visualizer.show()
212+
audio_visualizer.start_visualization()
213+
app.exec_()
214+
```
215+
216+
Once you have activated the audio_visualizer instance, feel free to use it wherever in the program. It consists of several parameters (which gives more control to the user), so make sure to configure and add those before using it in your code. Also, the user can modify (wrt [v4.0](https://github.com/AdityaSeth777/Audio-SpectraCLI/tree/4.0)) the Duration (in seconds), Sampling Rate (in Hz), and Block Size.
217+
218+
## Upcoming Features
219+
220+
- Save and Export: Implement functionality to save the generated spectrum as an image file or export data for further analysis.
221+
- CLI endpoints.
222+
- Option to choose between CLI/GUI.
223+
224+
---
225+
226+
## For contributing
227+
228+
Check the [Contributing page.](https://github.com/AdityaSeth777/Audio-SpectraCLI/blob/main/Contributing.md)
229+
230+
## License
231+
232+
[MIT © Aditya Seth](https://github.com/AdityaSeth777/Audio-SpectraCLI/blob/main/LICENSE)
233+
234+
## What next?
235+
236+
I will be improving this project.
237+
238+
## Where to contact ?
239+
240+
Contact: [contact@adityaseth.in](mailto:contact@adityaseth.in?subject=Email%20owing%20to%20adityaseth.in&body=Greetings%2C%0AI%20am%20%5Bname%5D.%20I%20just%20came%20across%20your%20website%20and%20was%20hoping%20to%20talk%20to%20you%20about%20something.)
241+
242+
## 🙋‍♂️ Support
243+
244+
💙 If you like this project, give it a ⭐ and share it with friends! <br><br>
245+
246+
[<img width="200" height="70" src="https://i.postimg.cc/R0cqPmDf/bmc-button.png" alt="buymeacoffee">](https://www.buymeacoffee.com/adityaseth)
247+
248+
---
249+
250+
# Made with <img width="40" height="40" src="https://img.icons8.com/clouds/100/love-circled.png" alt="love-circled"/> and <img width="40" height="40" src="https://img.icons8.com/clouds/100/python.png" alt="python"/>

Audio_SpectraCLI.egg-info/SOURCES.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
LICENSE
2+
setup.cfg
3+
setup.py
4+
Audio_SpectraCLI/__init__.py
5+
Audio_SpectraCLI/main-old.py
6+
Audio_SpectraCLI/main.py
7+
Audio_SpectraCLI.egg-info/PKG-INFO
8+
Audio_SpectraCLI.egg-info/SOURCES.txt
9+
Audio_SpectraCLI.egg-info/dependency_links.txt
10+
Audio_SpectraCLI.egg-info/requires.txt
11+
Audio_SpectraCLI.egg-info/top_level.txt
12+
tests/test-old.py
13+
tests/test.py
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
numpy
2+
matplotlib
3+
sounddevice
4+
tabulate
5+
setuptools
6+
twine
7+
wheel
8+
pyqt5
9+
pyaudio
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Audio_SpectraCLI
Binary file not shown.
Binary file not shown.

Audio_SpectraCLI/main-old.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Aditya Seth
2+
# Description: This file contains the main code for the Audio-SpectraCLI project. It is responsible for creating the AudioSpectrumVisualizer class which is used to visualize the audio spectrum in real-time.
3+
4+
import numpy as np
5+
import matplotlib.pyplot as plt
6+
import sounddevice as sd
7+
import queue
8+
import threading
9+
import time
10+
11+
12+
class AudioSpectrumVisualizer:
13+
def __init__(self, duration=10, fs=44100, block_size=2048, frequency_range=(20, 20000), color='blue'):
14+
self.duration = duration
15+
self.fs = fs
16+
self.block_size = block_size
17+
self.num_blocks = int(duration * fs / block_size)
18+
self.frequency_range = frequency_range
19+
self.color = color
20+
self.audio_queue = queue.Queue()
21+
22+
def audio_callback(self, indata, frames, time, status):
23+
if status:
24+
print(status)
25+
self.audio_queue.put(indata.copy())
26+
27+
def process_audio(self):
28+
freq_bins = np.fft.fftfreq(self.block_size, 1/self.fs)
29+
spectrum = np.zeros(self.block_size)
30+
31+
plt.ion()
32+
fig, ax = plt.subplots()
33+
x = np.arange(0, self.block_size)
34+
line, = ax.plot(freq_bins, spectrum, color=self.color)
35+
ax.set_xlim(self.frequency_range)
36+
ax.set_ylim(0, 0.1)
37+
ax.set_xlabel('Frequency (Hz)')
38+
ax.set_ylabel('Magnitude')
39+
40+
while True:
41+
audio_block = self.audio_queue.get()
42+
spectrum = np.abs(np.fft.fft(audio_block[:, 0], n=self.block_size))
43+
max_magnitude = np.max(spectrum)
44+
if max_magnitude > ax.get_ylim()[1]:
45+
ax.set_ylim(0, max_magnitude * 1.1)
46+
line.set_ydata(spectrum)
47+
fig.canvas.draw()
48+
fig.canvas.flush_events()
49+
50+
def start_visualization(self):
51+
audio_thread = threading.Thread(target=self.process_audio, daemon=True)
52+
audio_thread.start()
53+
54+
with sd.InputStream(callback=self.audio_callback, channels=1, samplerate=self.fs):
55+
while True:
56+
time.sleep(1)
57+
58+
audio_thread.join()
59+
60+
61+
# List of functions available for use:
62+
__all__ = ['AudioSpectrumVisualizer']

0 commit comments

Comments
 (0)