From 45fd627cf4734a576005310b1ca942759ec5787a Mon Sep 17 00:00:00 2001 From: AdityaSeth777 Date: Wed, 28 Feb 2024 03:27:25 +0530 Subject: [PATCH 1/4] typo in cfg --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index f6b9551..65510cc 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = Audio-SpectraCLI -version = 0.1 +version = 2.1 author = Aditya Seth author_email = setha4195@gmail.com description = AudioSpectraCLI is a command-line tool that provides real-time FFT visualization of audio spectra. It captures audio input from the microphone and displays the corresponding frequency spectrum directly in the terminal window, allowing users to monitor and analyze audio signals without the need for graphical interfaces. From 1f9696fb751a710bc9f4af39155cfd55c3966168 Mon Sep 17 00:00:00 2001 From: AdityaSeth777 Date: Thu, 21 Mar 2024 04:25:26 +0530 Subject: [PATCH 2/4] trying out some new functions. just some initial thinking --- Audio_SpectraCLI/main.py | 71 ++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/Audio_SpectraCLI/main.py b/Audio_SpectraCLI/main.py index 5329f76..f69905a 100644 --- a/Audio_SpectraCLI/main.py +++ b/Audio_SpectraCLI/main.py @@ -1,40 +1,42 @@ -# main.py - -def audio_visualizer(): - import numpy as np - import matplotlib.pyplot as plt - import sounddevice as sd - import queue - import threading - import time - duration = 10 - fs = 44100 - block_size = 2048 - num_blocks = int(duration * fs / block_size) - - audio_queue = queue.Queue() - - def audio_callback(indata, frames, time, status): +import numpy as np +import matplotlib.pyplot as plt +import sounddevice as sd +import queue +import threading +import time + + +class AudioSpectrumVisualizer: + def __init__(self, duration=10, fs=44100, block_size=2048, frequency_range=(20, 20000), color='blue'): + self.duration = duration + self.fs = fs + self.block_size = block_size + self.num_blocks = int(duration * fs / block_size) + self.frequency_range = frequency_range + self.color = color + self.audio_queue = queue.Queue() + + def audio_callback(self, indata, frames, time, status): if status: print(status) - audio_queue.put(indata.copy()) + self.audio_queue.put(indata.copy()) - def process_audio(): - freq_bins = np.fft.fftfreq(block_size, 1/fs) - spectrum = np.zeros(block_size) + def process_audio(self): + freq_bins = np.fft.fftfreq(self.block_size, 1/self.fs) + spectrum = np.zeros(self.block_size) plt.ion() fig, ax = plt.subplots() - x = np.arange(0, block_size) - line, = ax.plot(freq_bins, spectrum) - ax.set_xlim(0, 5000) + x = np.arange(0, self.block_size) + line, = ax.plot(freq_bins, spectrum, color=self.color) + ax.set_xlim(self.frequency_range) ax.set_ylim(0, 0.1) ax.set_xlabel('Frequency (Hz)') ax.set_ylabel('Magnitude') while True: - audio_block = audio_queue.get() - spectrum = np.abs(np.fft.fft(audio_block[:, 0], n=block_size)) + audio_block = self.audio_queue.get() + spectrum = np.abs(np.fft.fft(audio_block[:, 0], n=self.block_size)) max_magnitude = np.max(spectrum) if max_magnitude > ax.get_ylim()[1]: ax.set_ylim(0, max_magnitude * 1.1) @@ -42,11 +44,16 @@ def process_audio(): fig.canvas.draw() fig.canvas.flush_events() - audio_thread = threading.Thread(target=process_audio, daemon=True) - audio_thread.start() + def start_visualization(self): + audio_thread = threading.Thread(target=self.process_audio, daemon=True) + audio_thread.start() + + with sd.InputStream(callback=self.audio_callback, channels=1, samplerate=self.fs): + while True: + time.sleep(1) + + audio_thread.join() - with sd.InputStream(callback=audio_callback, channels=1, samplerate=fs): - while True: - time.sleep(1) - audio_thread.join() +# List of functions available for use: +__all__ = ['AudioSpectrumVisualizer'] From f581af51cab2e7e943a08188e341a7ca31babc3e Mon Sep 17 00:00:00 2001 From: AdityaSeth777 Date: Thu, 28 Mar 2024 19:08:55 +0530 Subject: [PATCH 3/4] Added customizable frequency range and color customization --- Audio_SpectraCLI.egg-info/PKG-INFO | 114 ++++++++++++++++++ Audio_SpectraCLI.egg-info/SOURCES.txt | 10 ++ .../dependency_links.txt | 1 + Audio_SpectraCLI.egg-info/requires.txt | 8 ++ Audio_SpectraCLI.egg-info/top_level.txt | 1 + Audio_SpectraCLI/__init__.py | 2 +- Audio_SpectraCLI/main.py | 3 + Readme.md | 3 - setup.cfg | 2 +- setup.py | 4 +- tests/main.py | 9 +- 11 files changed, 148 insertions(+), 9 deletions(-) create mode 100644 Audio_SpectraCLI.egg-info/PKG-INFO create mode 100644 Audio_SpectraCLI.egg-info/SOURCES.txt create mode 100644 Audio_SpectraCLI.egg-info/dependency_links.txt create mode 100644 Audio_SpectraCLI.egg-info/requires.txt create mode 100644 Audio_SpectraCLI.egg-info/top_level.txt diff --git a/Audio_SpectraCLI.egg-info/PKG-INFO b/Audio_SpectraCLI.egg-info/PKG-INFO new file mode 100644 index 0000000..33dbf81 --- /dev/null +++ b/Audio_SpectraCLI.egg-info/PKG-INFO @@ -0,0 +1,114 @@ +Metadata-Version: 2.1 +Name: Audio_SpectraCLI +Version: 2.2 +Summary: AudioSpectraCLI is a command-line tool that provides real-time FFT visualization of audio spectra. It captures audio input from the microphone and displays the corresponding frequency spectrum directly in the terminal window, allowing users to monitor and analyze audio signals without the need for graphical interfaces. +Home-page: https://github.com/AdityaSeth777/Audio-SpectraCLI +Author: Aditya Seth +Author-email: setha4195@gmail.com +License: MIT +Description-Content-Type: text/markdown +License-File: LICENSE +Requires-Dist: numpy +Requires-Dist: matplotlib +Requires-Dist: sounddevice +Requires-Dist: tabulate +Requires-Dist: setuptools +Requires-Dist: twine +Requires-Dist: wheel +Requires-Dist: pyaudio + +``` + _ _ _ ____ _ ____ _ ___ + / \ _ _ __| (_) ___ / ___| _ __ ___ ___| |_ _ __ __ _ / ___| | |_ _| + / _ \| | | |/ _` | |/ _ \ ____\___ \| '_ \ / _ \/ __| __| '__/ _` | | | | | | + / ___ \ |_| | (_| | | (_) |_____|__) | |_) | __/ (__| |_| | | (_| | |___| |___ | | +/_/ \_\__,_|\__,_|_|\___/ |____/| .__/ \___|\___|\__|_| \__,_|\____|_____|___| + |_| +``` + +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 CLI interface for users to start the visualization and exit the program. + +## Features + +- Real-time audio spectrum visualization. +- Interactive CLI menu for easy navigation. +- Cross-platform compatibility (works on Windows, macOS, and Linux). + +## Packaging + +``` +Audio-SpectraCLI/ + +│ CODE_OF_CONDUCT.md +│ Contributing.md +│ LICENSE +│ Readme.md +│ requirements.txt +│ setup.cfg +│ setup.py +│ +├───.github +│ └───workflows +│ python-publish.yml +│ +├───Audio_SpectraCLI +│ main.py +│ __init__.py +│ +└───tests + main.py +``` + +## Installation & Usage + +1. Install using pip + +``` +pip install Audio-SpectraCLI +``` + +2. Import and use modules + +``` +from Audio_SpectraCLI import audio_visualizer +``` + +--- + +## Upcoming Features + +- CLI endpoints +- Save and Export: Implement functionality to save the generated spectrum as an image file or export data for further analysis. +- Additional Audio Effects: Integrate additional audio effects or processing options to enhance the visualization. + +--- + +## For contributing + +Check the [Contributing page.](https://github.com/AdityaSeth777/Audio-SpectraCLI/blob/main/Contributing.md) +Make sure to PR your changes in the development branch. + +## .env file + +This file contains various environment variables that you can configure. + +## License + +[MIT © Aditya Seth](https://github.com/AdityaSeth777/Audio-SpectraCLI/blob/main/LICENSE) + +## What next? + +I will be improving this project. + +## Where to contact ? + +Contact: [contact@adityaseth.in] + +## 🙋‍♂️ Support + +💙 If you like this project, give it a ⭐ and share it with friends!

+[☕ Buy me a coffee](https://www.buymeacoffee.com/adityaseth) + +--- + +Made with ❤️ diff --git a/Audio_SpectraCLI.egg-info/SOURCES.txt b/Audio_SpectraCLI.egg-info/SOURCES.txt new file mode 100644 index 0000000..6327166 --- /dev/null +++ b/Audio_SpectraCLI.egg-info/SOURCES.txt @@ -0,0 +1,10 @@ +LICENSE +setup.cfg +setup.py +Audio_SpectraCLI/__init__.py +Audio_SpectraCLI/main.py +Audio_SpectraCLI.egg-info/PKG-INFO +Audio_SpectraCLI.egg-info/SOURCES.txt +Audio_SpectraCLI.egg-info/dependency_links.txt +Audio_SpectraCLI.egg-info/requires.txt +Audio_SpectraCLI.egg-info/top_level.txt \ No newline at end of file diff --git a/Audio_SpectraCLI.egg-info/dependency_links.txt b/Audio_SpectraCLI.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Audio_SpectraCLI.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/Audio_SpectraCLI.egg-info/requires.txt b/Audio_SpectraCLI.egg-info/requires.txt new file mode 100644 index 0000000..6f8ef19 --- /dev/null +++ b/Audio_SpectraCLI.egg-info/requires.txt @@ -0,0 +1,8 @@ +numpy +matplotlib +sounddevice +tabulate +setuptools +twine +wheel +pyaudio diff --git a/Audio_SpectraCLI.egg-info/top_level.txt b/Audio_SpectraCLI.egg-info/top_level.txt new file mode 100644 index 0000000..62e5e68 --- /dev/null +++ b/Audio_SpectraCLI.egg-info/top_level.txt @@ -0,0 +1 @@ +Audio_SpectraCLI diff --git a/Audio_SpectraCLI/__init__.py b/Audio_SpectraCLI/__init__.py index 7ccf813..b28a9fd 100644 --- a/Audio_SpectraCLI/__init__.py +++ b/Audio_SpectraCLI/__init__.py @@ -1,3 +1,3 @@ # __init__.py -from .main import audio_visualizer +from .main import AudioSpectrumVisualizer diff --git a/Audio_SpectraCLI/main.py b/Audio_SpectraCLI/main.py index f69905a..12149c3 100644 --- a/Audio_SpectraCLI/main.py +++ b/Audio_SpectraCLI/main.py @@ -1,3 +1,6 @@ +# Aditya Seth +# 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. + import numpy as np import matplotlib.pyplot as plt import sounddevice as sd diff --git a/Readme.md b/Readme.md index c8e607c..33e6ee7 100644 --- a/Readme.md +++ b/Readme.md @@ -9,7 +9,6 @@ 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 CLI interface for users to start the visualization and exit the program. - ## Features - Real-time audio spectrum visualization. @@ -60,8 +59,6 @@ from Audio_SpectraCLI import audio_visualizer ## Upcoming Features - CLI endpoints -- Customizable Frequency Range: Allow users to specify the frequency range to display in the spectrum. -- Color Customization: Provide options for users to customize the colors used in the spectrum visualization. - Save and Export: Implement functionality to save the generated spectrum as an image file or export data for further analysis. - Additional Audio Effects: Integrate additional audio effects or processing options to enhance the visualization. diff --git a/setup.cfg b/setup.cfg index 65510cc..66177a3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = Audio-SpectraCLI -version = 2.1 +version = 2.2 author = Aditya Seth author_email = setha4195@gmail.com description = AudioSpectraCLI is a command-line tool that provides real-time FFT visualization of audio spectra. It captures audio input from the microphone and displays the corresponding frequency spectrum directly in the terminal window, allowing users to monitor and analyze audio signals without the need for graphical interfaces. diff --git a/setup.py b/setup.py index 956f75c..358a0b2 100644 --- a/setup.py +++ b/setup.py @@ -2,9 +2,9 @@ setup( name='Audio_SpectraCLI', - version='2.1', + version='2.2', author="Aditya Seth", - long_description=open('Readme.md').read(), + long_description=open('Readme.md', encoding='utf-8').read(), long_description_content_type='text/markdown', packages=find_packages(), install_requires=[ diff --git a/tests/main.py b/tests/main.py index 3415668..2b2b6b5 100644 --- a/tests/main.py +++ b/tests/main.py @@ -1,3 +1,8 @@ -from Audio_SpectraCLI import audio_visualizer +from Audio_SpectraCLI import AudioSpectrumVisualizer -audio_visualizer() +# Create an instance of AudioSpectrumVisualizer with custom parameters +audio_visualizer = AudioSpectrumVisualizer( + duration=5, frequency_range=(50, 5000), color='red') + +# Start the audio spectrum visualization +audio_visualizer.start_visualization() From 9e041a49a724718e44cd0bb1e52d644635fbf1c8 Mon Sep 17 00:00:00 2001 From: AdityaSeth777 Date: Thu, 28 Mar 2024 19:23:47 +0530 Subject: [PATCH 4/4] Good to go. --- Audio_SpectraCLI.egg-info/PKG-INFO | 114 ------------------ Audio_SpectraCLI.egg-info/SOURCES.txt | 10 -- .../dependency_links.txt | 1 - Audio_SpectraCLI.egg-info/requires.txt | 8 -- Audio_SpectraCLI.egg-info/top_level.txt | 1 - Readme.md | 27 ++++- setup.cfg | 2 +- 7 files changed, 22 insertions(+), 141 deletions(-) delete mode 100644 Audio_SpectraCLI.egg-info/PKG-INFO delete mode 100644 Audio_SpectraCLI.egg-info/SOURCES.txt delete mode 100644 Audio_SpectraCLI.egg-info/dependency_links.txt delete mode 100644 Audio_SpectraCLI.egg-info/requires.txt delete mode 100644 Audio_SpectraCLI.egg-info/top_level.txt diff --git a/Audio_SpectraCLI.egg-info/PKG-INFO b/Audio_SpectraCLI.egg-info/PKG-INFO deleted file mode 100644 index 33dbf81..0000000 --- a/Audio_SpectraCLI.egg-info/PKG-INFO +++ /dev/null @@ -1,114 +0,0 @@ -Metadata-Version: 2.1 -Name: Audio_SpectraCLI -Version: 2.2 -Summary: AudioSpectraCLI is a command-line tool that provides real-time FFT visualization of audio spectra. It captures audio input from the microphone and displays the corresponding frequency spectrum directly in the terminal window, allowing users to monitor and analyze audio signals without the need for graphical interfaces. -Home-page: https://github.com/AdityaSeth777/Audio-SpectraCLI -Author: Aditya Seth -Author-email: setha4195@gmail.com -License: MIT -Description-Content-Type: text/markdown -License-File: LICENSE -Requires-Dist: numpy -Requires-Dist: matplotlib -Requires-Dist: sounddevice -Requires-Dist: tabulate -Requires-Dist: setuptools -Requires-Dist: twine -Requires-Dist: wheel -Requires-Dist: pyaudio - -``` - _ _ _ ____ _ ____ _ ___ - / \ _ _ __| (_) ___ / ___| _ __ ___ ___| |_ _ __ __ _ / ___| | |_ _| - / _ \| | | |/ _` | |/ _ \ ____\___ \| '_ \ / _ \/ __| __| '__/ _` | | | | | | - / ___ \ |_| | (_| | | (_) |_____|__) | |_) | __/ (__| |_| | | (_| | |___| |___ | | -/_/ \_\__,_|\__,_|_|\___/ |____/| .__/ \___|\___|\__|_| \__,_|\____|_____|___| - |_| -``` - -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 CLI interface for users to start the visualization and exit the program. - -## Features - -- Real-time audio spectrum visualization. -- Interactive CLI menu for easy navigation. -- Cross-platform compatibility (works on Windows, macOS, and Linux). - -## Packaging - -``` -Audio-SpectraCLI/ - -│ CODE_OF_CONDUCT.md -│ Contributing.md -│ LICENSE -│ Readme.md -│ requirements.txt -│ setup.cfg -│ setup.py -│ -├───.github -│ └───workflows -│ python-publish.yml -│ -├───Audio_SpectraCLI -│ main.py -│ __init__.py -│ -└───tests - main.py -``` - -## Installation & Usage - -1. Install using pip - -``` -pip install Audio-SpectraCLI -``` - -2. Import and use modules - -``` -from Audio_SpectraCLI import audio_visualizer -``` - ---- - -## Upcoming Features - -- CLI endpoints -- Save and Export: Implement functionality to save the generated spectrum as an image file or export data for further analysis. -- Additional Audio Effects: Integrate additional audio effects or processing options to enhance the visualization. - ---- - -## For contributing - -Check the [Contributing page.](https://github.com/AdityaSeth777/Audio-SpectraCLI/blob/main/Contributing.md) -Make sure to PR your changes in the development branch. - -## .env file - -This file contains various environment variables that you can configure. - -## License - -[MIT © Aditya Seth](https://github.com/AdityaSeth777/Audio-SpectraCLI/blob/main/LICENSE) - -## What next? - -I will be improving this project. - -## Where to contact ? - -Contact: [contact@adityaseth.in] - -## 🙋‍♂️ Support - -💙 If you like this project, give it a ⭐ and share it with friends!

-[☕ Buy me a coffee](https://www.buymeacoffee.com/adityaseth) - ---- - -Made with ❤️ diff --git a/Audio_SpectraCLI.egg-info/SOURCES.txt b/Audio_SpectraCLI.egg-info/SOURCES.txt deleted file mode 100644 index 6327166..0000000 --- a/Audio_SpectraCLI.egg-info/SOURCES.txt +++ /dev/null @@ -1,10 +0,0 @@ -LICENSE -setup.cfg -setup.py -Audio_SpectraCLI/__init__.py -Audio_SpectraCLI/main.py -Audio_SpectraCLI.egg-info/PKG-INFO -Audio_SpectraCLI.egg-info/SOURCES.txt -Audio_SpectraCLI.egg-info/dependency_links.txt -Audio_SpectraCLI.egg-info/requires.txt -Audio_SpectraCLI.egg-info/top_level.txt \ No newline at end of file diff --git a/Audio_SpectraCLI.egg-info/dependency_links.txt b/Audio_SpectraCLI.egg-info/dependency_links.txt deleted file mode 100644 index 8b13789..0000000 --- a/Audio_SpectraCLI.egg-info/dependency_links.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Audio_SpectraCLI.egg-info/requires.txt b/Audio_SpectraCLI.egg-info/requires.txt deleted file mode 100644 index 6f8ef19..0000000 --- a/Audio_SpectraCLI.egg-info/requires.txt +++ /dev/null @@ -1,8 +0,0 @@ -numpy -matplotlib -sounddevice -tabulate -setuptools -twine -wheel -pyaudio diff --git a/Audio_SpectraCLI.egg-info/top_level.txt b/Audio_SpectraCLI.egg-info/top_level.txt deleted file mode 100644 index 62e5e68..0000000 --- a/Audio_SpectraCLI.egg-info/top_level.txt +++ /dev/null @@ -1 +0,0 @@ -Audio_SpectraCLI diff --git a/Readme.md b/Readme.md index 33e6ee7..189a0c2 100644 --- a/Readme.md +++ b/Readme.md @@ -9,11 +9,13 @@ 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 CLI interface for users to start the visualization and exit the program. -## Features +## Current Features (with respect to 2.2) -- Real-time audio spectrum visualization. -- Interactive CLI menu for easy navigation. -- Cross-platform compatibility (works on Windows, macOS, and Linux). +- Real-time visualization of Fast Fourier Transform (FFT) spectrum of audio input. +- Support for adjusting parameters such as duration, sampling rate, and block size. +- Seamless integration with SoundDevice for audio input capture. +- Customizable Frequency Range: Allow users to specify the frequency range to display in the spectrum. +- Color Customization: Provide options for users to customize the colors used in the spectrum visualization. ## Packaging @@ -50,15 +52,28 @@ pip install Audio-SpectraCLI 2. Import and use modules +- Create a Python file. +- You can use [Example.py](./tests/main.py) as a reference or use the following code : + ``` -from Audio_SpectraCLI import audio_visualizer +from Audio_SpectraCLI import AudioSpectrumVisualizer + +# Creating an instance of AudioSpectrumVisualizer with custom parameters. +audio_visualizer = AudioSpectrumVisualizer( + duration=5, frequency_range=(50, 5000), color='red') + +# Starting the audio spectrum visualization +audio_visualizer.start_visualization() ``` +- 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. + --- ## Upcoming Features -- CLI endpoints +- CLI endpoints. +- Option to choose between CLI/GUI. - Save and Export: Implement functionality to save the generated spectrum as an image file or export data for further analysis. - Additional Audio Effects: Integrate additional audio effects or processing options to enhance the visualization. diff --git a/setup.cfg b/setup.cfg index 66177a3..7cea251 100644 --- a/setup.cfg +++ b/setup.cfg @@ -2,7 +2,7 @@ name = Audio-SpectraCLI version = 2.2 author = Aditya Seth -author_email = setha4195@gmail.com +author_email = contact@adityaseth.in description = AudioSpectraCLI is a command-line tool that provides real-time FFT visualization of audio spectra. It captures audio input from the microphone and displays the corresponding frequency spectrum directly in the terminal window, allowing users to monitor and analyze audio signals without the need for graphical interfaces. license = MIT home-page = https://github.com/AdityaSeth777/Audio-SpectraCLI \ No newline at end of file