Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

crear ondas segun musica python

import math        #import needed modules
import pyaudio     #Sudo apt-get install python-pyaudio

PyAudio = pyaudio.PyAudio     #initialize pyaudio

#See https://en.wikipedia.org/wiki/Bit_rate#Audio
BITRATE = 16000     #number of frames per second/frameset.      

FREQUENCY = 500     #Hz, waves per second, 261.63=C4-note.
LENGTH = 1     #seconds to play sound

if FREQUENCY > BITRATE:
    BITRATE = FREQUENCY+100

NUMBEROFFRAMES = int(BITRATE * LENGTH)
RESTFRAMES = NUMBEROFFRAMES % BITRATE
WAVEDATA = ''    

#generating wawes
for x in xrange(NUMBEROFFRAMES):
 WAVEDATA = WAVEDATA+chr(int(math.sin(x/((BITRATE/FREQUENCY)/math.pi))*127+128))    

for x in xrange(RESTFRAMES): 
 WAVEDATA = WAVEDATA+chr(128)

p = PyAudio()
stream = p.open(format = p.get_format_from_width(1), 
                channels = 1, 
                rate = BITRATE, 
                output = True)

stream.write(WAVEDATA)
stream.stop_stream()
stream.close()
p.terminate()
Comment

PREVIOUS NEXT
Code Example
Python :: hpw to create related model in django rest framework logic 
Python :: remove repetitive characters from the specified column of a given DataFrame 
Python :: spark dataframe without column 
Python :: django filter word count greater than 
Python :: sklearn recognising sentences 
Python :: send operator by parameter python 
Python :: python read stdin to string 
Python :: add sign to y axis values python 
Python :: inspect last 5 rows of dataframe 
Python :: dfs and bfs inn python 
Python :: discord.py get channel object from id 
Python :: python program to check fibonacci number using functions 
Python :: when was python 3 released 
Python :: python sum over specific indexes 
Python :: python selenium for desktop application 
Python :: polycarp and coins codeforces solution 
Python :: test api register user 
Python :: np.conjugate 
Python :: mechanize python XE #26 
Python :: Location of matploitlibrc file 
Python :: python dynamic csvnfile joining 
Python :: get inverse of bool value python 
Python :: .format() multiple placeholders 
Python :: get dataframe deminsions 
Python :: separating numeric and categorical feature using loop 
Python :: split list in two based on condition python 
Python :: Python Switch case statement using if-elif-else 
Python :: check type of exception 
Python :: codeforces 1133A in python 
Python :: python sumproduct excel 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =