Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pyaudio get system audio

"""PyAudio example: Record a few seconds of audio and save to a WAVE file."""

import pyaudio
import wave

CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = "output.wav"

p = pyaudio.PyAudio()

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

print("* recording")

frames = []

for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
    data = stream.read(CHUNK)
    frames.append(data)

print("* done recording")

stream.stop_stream()
stream.close()
p.terminate()

wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
wf.setnchannels(CHANNELS)
wf.setsampwidth(p.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(b''.join(frames))
wf.close()
Comment

PREVIOUS NEXT
Code Example
Python :: buscar elemento en lista python 
Python :: read sharepoint list using python 
Python :: Filling or replacing the missing values with mode 
Python :: fix the error when you close turtle screen in your own main loop 
Python :: Collecting package metadata (repodata.json): done Solving environment: failed ResolvePackageNotFound: - python==3.9.13 
Python :: are you dumb python program 
Python :: 1045 - Triangle Types 
Python :: Horizontal concatication 
Python :: insert key in binary tree recursively 
Python :: python loop through specific angle 
Python :: python multiprocessing imap tqdm 
Python :: pandas fast way to view distribution by group 
Python :: kivy bind when text changes 
Python :: plt.text background alpha 
Python :: calculate speed with time in datetime python 
Python :: tf.io path copy 
Python :: when i was a young lad i was bitten by a turtle 
Python :: frogenset ito list pandas 
Python :: python output parameter 
Python :: getting heading from a webpage in beautifulsoup 
Python :: pylatex add section without numbering 
Python :: concatenate dataframes using one column 
Python :: Return the key-value pairs in this RDD to the master as a dictionary. 
Python :: Gets an existing SparkSession or, if there is no existing one, creates a new one based on the options set in this builder 
Python :: couple legend from twin axes python 
Python :: slicing time series 
Python :: add input to list python 
Python :: matplotlib text relative to axis 
Python :: how to get list from comma separated string in python 
Python :: python multiple items in with statment 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =