Giter VIP home page Giter VIP logo

audioprocessing's Introduction

Audio Processing

This script demonstrates how to record audio from a microphone using the PyAudio library in Python and save it as a WAV file. Here is a step-by-step description of what the code does:

Importing Required Libraries:

  • pyaudio: This library provides Python bindings for PortAudio, a cross-platform audio I/O library.
  • wave: This library is used to read and write WAV files.

Creating a PyAudio Instance:

p = pyaudio.PyAudio()

Setting Audio Parameters:

  • FORMAT: Specifies the audio format (16-bit PCM in this case).
  • FS: The sampling frequency (44100 Hz, which is CD quality).
  • CHANNELS: The number of audio channels (1 for mono).
  • CHUNK: The size of each audio chunk (1024 frames).
  • RECORD_SECOND: Duration of the recording in seconds (3 seconds).

Opening an Audio Stream:

stream = p.open(format=FORMAT, channels=CHANNELS, rate=FS, input=True, frames_per_buffer=CHUNK)

Recording Audio:

  • A list frames is initialized to store the recorded audio data.
  • num_times calculates the number of chunks to be recorded based on the duration and chunk size.
  • A loop reads the audio data from the stream in chunks and appends it to the frames list.

Starting and Closing the Stream:

stream.start_stream()
stream.close()
p.terminate()

Outputting Recorded Data:

  • The frames list, which contains the recorded audio data, is printed.

Writing Audio Data to a WAV File:

  • samplewidth retrieves the sample size of the audio format.
  • A new WAV file output.wav is created.
  • The number of channels, sample width, and frame rate are set.
  • The recorded frames are written to the WAV file.
  • The WAV file is closed.

This snippet includes all necessary details about the parameters and the steps taken in the code.

audioprocessing's People

Contributors

yiyongwei1216 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.