I'm playing around with high-pitched sounds. I'd like to generate an MP3 file with a 1 second 15Khz burst. Is there a simple way to do this from C or Python? I don't want to use MATLAB.
You could use Python's wave
module to create a wave file which you could then compress to MP3. To create a one second 15khz sine wave:
import math
import wave
import struct
nchannels = 1
sampwidth = 2
framerate = 44100
nframes = 44100
comptype = "NONE"
compname = "not compressed"
amplitude = 4000
frequency = 15000
wav_file = wave.open('15khz_sine.wav', 'w')
wav_file.setparams((nchannels, sampwidth, framerate, nframes, comptype, compname))
for i in xrange(nframes):
sample = math.sin(2*math.pi*frequency*(float(i)/framerate))*amplitude/2
wav_file.writeframes(struct.pack('h', sample))
wav_file.close()
I would break this into 2 pieces:
-t
for converting wave to mp3.One thing to note is 15KHz is very high frequency to be heard by human and I guess most of speakers are not capable of playing it as it is beyond cutoff frequency of them. So don't be surprised if you don't hear the result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With