Create a sound file with a 15 kHz tone

I play with high sounds. I would like to generate an MP3 file with a 1 second burst of 15 kHz. Is there an easy way to do this with C or Python? I do not want to use MATLAB.

+8
c python audio mp3
source share
3 answers

You can use Python wave to create a wave file that you could compress to MP3. To create one second 15 kHz 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() 
+14
source share

I would break it into 2 parts:

  • Create a wave file using the C ++ library (e.g. libsndfile )
  • Convert the wave file to mp3 using a utility (e.g. lame ). This is a command line tool that can also be called from your C program. See -t to convert wave to mp3.

It should be noted that 15 kHz is a very high frequency to be heard by a person, and I think that most speakers are not able to play it, because it is outside the cutoff frequency. Therefore, do not be surprised if you do not hear the result.

+2
source share

You tried:

 #include<dos.h> #include<iostream.h> #include<conio.h> main() { sound(500); // Frequency delay(1000); // Time nosound(); // Stop } 
-one
source share

All Articles