Skip to content

Recording ๐ŸŽค , playing ๐Ÿ”Š , and visualizing ๐Ÿ“Š audio waveforms using sounddevice, pygame, and matplotlib.

License

Notifications You must be signed in to change notification settings

ansarialireza/SpeechSignalVisualization

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

6 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Speech Signal Visualization ๐ŸŽต

This Python script, implemented as a class-based audio processor, provides functionality for recording audio, playing it back, and visualizing the waveform using sounddevice, pygame, and matplotlib.

Dependencies

Install the dependencies using:

pip install -r requirements.txt

Make sure to create a virtual environment and activate it before installing the dependencies.

Usage

  1. Clone the repository:
git clone https://github.com/ansarialireza/SpeechSignalVisualization.git
cd SpeechSignalVisualization
  1. Run the script:
python audio_processor.py

Adjust the duration variable in the script to change the recording length.

Class: AudioProcessor

import sounddevice as sd
import numpy as np
import pygame
import matplotlib.pyplot as plt
import random

class AudioProcessor:
    def __init__(self, sample_rate=44100):
        # ...

    def record_audio(self, duration):
        # ...

    def play_audio(self, audio_data):
        # ...

    def plot_audio_waveform(self, audio_data, save_plot=True, plot_filename='audio_waveform.png'):
        # ...

Methods

1. record_audio(duration)

Records audio for the specified duration.

2. play_audio(audio_data)

Plays back the recorded audio using pygame.

3. plot_audio_waveform(audio_data, save_plot=True, plot_filename='audio_waveform.png')

Plots and optionally saves the audio waveform using matplotlib.

Example

if __name__ == "__main__":
    audio_processor = AudioProcessor()
    duration = 5
    recorded_audio = audio_processor.record_audio(duration)
    audio_processor.play_audio(recorded_audio)
    audio_processor.plot_audio_waveform(recorded_audio)

This script records audio for 5 seconds, plays it back, and plots the waveform.

The waveform image (audio_waveform.png) is saved in the same directory as the script and displayed below:

Audio Waveform

You can find the visual representation of the recorded audio waveform in this image.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Recording ๐ŸŽค , playing ๐Ÿ”Š , and visualizing ๐Ÿ“Š audio waveforms using sounddevice, pygame, and matplotlib.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages