casebeer / audiogen Goto Github PK
View Code? Open in Web Editor NEWPython generator based audio tools.
License: BSD 2-Clause "Simplified" License
Python generator based audio tools.
License: BSD 2-Clause "Simplified" License
When I run the following script using audiogen, the output wave file has a pitch that is double the specified frequency, and the silence duration is only .5 second instead of the expected 1 second. I've had a hard time tracking down the culprit for this... any ideas?
import audiogen
import itertools
def silence_tone(silence):
"""
parameter is length of time in seconds
"""
return itertools.chain( audiogen.silence(silence), audiogen.tone(440), )
def make_wave(destination):
output = audiogen.util.mixer(
# first parameter is all of the source generators
( silence_tone(0), silence_tone(1), ),
#next is a list of parameters for each channel
#to specify levels for each of the previous source generators:
(
(audiogen.util.constant(1), audiogen.util.constant(0)),
(audiogen.util.constant(0), audiogen.util.constant(1)),
)
)
with open(destination, "wb") as f:
#crop will set the maximum length of the file (so not infinite)
audiogen.sampler.write_wav(f, audiogen.util.crop(output, 2.0))
destination = "output.wav"
make_wave(destination)
Running Python 3.6.9
The following script:
#!/usr/bin/env python3
import audiogen
audiogen.sampler.play(audiogen.tone(440))
Generates the error:
jeff@machine:~$ ./test_audio.py
Traceback (most recent call last):
File "./test_audio.py", line 3, in <module>
import audiogen
File "/home/jeff/.local/lib/python3.6/site-packages/audiogen/__init__.py", line 2, in <module>
from .sampler import frame_rate
File "/home/jeff/.local/lib/python3.6/site-packages/audiogen/sampler.py", line 64
except IOError, e:
^
SyntaxError: invalid syntax
Line 64 in 184dee2
Hello,
It would be nice to make audiogen compatible with python 3.x
installing it with pip generates syntax errors :
Running setup.py install for audiogen
File "/usr/local/lib/python3.4/dist-packages/audiogen/util.py", line 28
print "cropping %d channel(s) to %d samples each" % (len(gens), seconds * sampler.FRAME_RATE)
^
SyntaxError: invalid syntax
File "/usr/local/lib/python3.4/dist-packages/audiogen/sampler.py", line 64
except IOError, e:
^
SyntaxError: invalid syntax
Hi I would like to generate 1 khz sine wave which I can do fine with this code
import math #import needed modules
import pyaudio #sudo apt-get install python-pyaudio
#List I/O Audio ports to use
#Input Device id 0 - Microsoft Sound Mapper - Input
#Input Device id 1 - Line 1 (Virtual Audio Cable)
#Input Device id 2 - Line 4 (Virtual Audio Cable)
#Input Device id 3 - Line In (Realtek High Definitio
#Input Device id 4 - Line 2 (Virtual Audio Cable)
#Input Device id 5 - Microphone (Realtek High Defini
#Input Device id 6 - Line 3 (Virtual Audio Cable)
#Output Device id 7 - Microsoft Sound Mapper - Output
#Output Device id 8 - Speakers (Realtek High Definiti
#Output Device id 9 - Line 1 (Virtual Audio Cable)
#Output Device id 10 - Line 3 (Virtual Audio Cable)
#Output Device id 11 - Line 2 (Virtual Audio Cable)
#Output Device id 12 - Line 4 (Virtual Audio Cable)
PyAudio = pyaudio.PyAudio #initialize pyaudio
#See https://en.wikipedia.org/wiki/Bit_rate#Audio
BITRATE = 192000 #number of frames per second/frameset.
FREQUENCY = 1000 #Hz, waves per second, 261.63=C4-note.
LENGTH = 10 #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()
#Open Device for streaming
stream = p.open(format = p.get_format_from_width(1),
channels = 1,
rate = BITRATE,
output = True,
output_device_index=9)
stream.write(WAVEDATA)
stream.stop_stream()
stream.close()
p.terminate()
the problem is that audio is plattered all over 192khz
what I would like to do is move this to 19khz and cut all the junk out of the signal so it would look more like this:
I thought I could acomplish this with audiogen and then play generated samples using pyaudio (since you added bandpass filter) but I don't realy know how would I do this
Thanks for Anwsering and Best Regards
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.