I have a numpy array that represents audio data(dtype is np.int16). Here is a plot of the audio data(me saying "one, two"):
the sampling rate is 100HZ. I saved this array into a wav file. However, the wav file is not audible from other music players(iTunes, vlc, Audacity etc). It's just complete silence.
Here is how I saved the array:
scipy.io.wavfile.write('output.wav',100,waveform) # 'waveform' is the numpy array
I am wondering what could the cause be ?
sampling rate too low?
amplitude not enough ? i tried to normalize to -32767 to 32767, but still no sound
Any help is appreciated
PS:
This is how the file looks in Audacity(I'm not very familiar with this software):
With a sampling frequency of 100Hz the highest audible frequency you get is 50Hz.
The range of human hearing is from about 20 to about 20000Hz.
For "telephone quality" you need 8000Hz and for "cd quality" you need 44100Hz (that is the standard sampling frequency for consumer audio).
Related
I'm analyzing 10 seconds of singing and wanted to know what the predominant frequencies were over the 10 seconds to see if the person is hitting them properly. For example if they were to "sing" do-re-mi-fa-so-la-si-do I'd like to know at what frequency they hit the tone and how closely that approximates to the theoretical frequency of that note (do=261hz, re=293hz, etc..)
I've tried working with the wave module in Python and breaking the WAV file into a numpy array, then slicing it into 0.1 second slices (WAV is sampled at 44kHz) and then calculate the predominant frequency in that time slice.
Is this the correct way of doing this?
I am working with wav files analysis using the librosa library in python. I used librosa.load() to load the audio file. Apparently this function loads the wav file into a numpy array with normalised amplitude values in the range -1 to 1. But I need to get the actual amplitude values for processing. How can I find that?
Thanks in advance!
You observed correctly that librosa always normalizes the samples to mono [-1:1] (and also 22050 Hz). That said, it's digital audio, so could multiply with whatever you want to get a different scale. If you insist, that your samples are on a scale of -2^15 to 2^15, simply multiply with 2^15. It pretty much means the same.
You won't gain anything, except dragging a peculiarity of the encoding audio format into your data.
That said, if that's what you want, you could use PySoundFile like this:
import soundfile as sf
y, sr = sf.read('existing_file.wav', dtype='int16')
The parameter dtype='int16' tells the library to assume a signed 16bit format per sample.
You can't. As Hendrik mentioned, the signal is digital and the amplitude in the WAV file won't tell you anything about the actual sound wave amplitude / sound power. That's completely lost the moment it was digitalised to WAV.
That being said, you can compute e.g. loudness, a relative perception of the sound power. If you are dealing with human auditory system, one of the recommended approaches is to:
Use to the Bark scale (Bark scale better reflects how we hear).
Compute energy in each bin.
(Optional) Normalise by the overall sum.
If you don't want to compute it yourself, check out e.g. YAAFE.
I have an audio clip, and I want to detect when a certain (high pitch) noise occurs. I don't know anything about FFT, how do I return the audio frame at which the noise occurs (I was thinking frequency trigger)?
Since you already have "scipy" there: You can compute a spectrogram to get frequencies over time for your sample (which you can load with wavfile.read.
You can then plot the spectrogram and figure out what the frequency you're looking for is.
Then
either loop over the spectrogram data itself to find the time where there's suitably strong signal in that frequency, or
filter your original signal first (a bandpass filter would be best) and then find the overall intense bits.
I want to make the vibration wave to the audio file.
I can get the amplitude data from the .wav file. but Now i have a series amplitude data that's not from the .wav file. the data is as the following:
2013-02-12T02:58:00.047803 -1286
2013-02-12T02:58:00.097803 -1271
2013-02-12T02:58:00.147803 -1297
......
and so on ,200 datas per 1s.
How do i change the datas into the .wav files in python?
Use wave module in combination with pyaudio. I am not sure though if it lets you create file with 200hz sampling frequency. 200hz sampling frequency can contain only < 100 Hz frequencies . That's not even good for lowest piano key
I have a song and I'd like to use Python to analyze it.
I need to find the "major sounds" in the song.
I use this term because I don't know the technical term for it, but here is what I mean:
https://www.youtube.com/watch?v=TYYyMu3pzL4
If you play the only first second of the song, I count about 4 major sounds.
In general, these are the same sounds that a person would hum if they were humming the song.
What are these called? And is there a function in librosa (or any other library/programming language) that can help me pinpoint their occurrence in a song?
I can provide more info/examples as needed.
UPDATE: After doing more research, I believe I am looking for what is called the "strongest beats". Librosa already has a beat_track function, but I think this gives you every single thing that can be called a beat in the song. I don't really want every beat, just the ones that stand out the most. The over-arching goal here is to create a music video where the major action happening on the screen lines up perfectly with the strongest beats. This creates a synergistic effect within the video - everything feels connected.
You would do well to call the process of parsing audio to identify its sonic archetypes acoustic fingerprinting
Audio has a time dimension so to witness your "major sounds" requires listening to the audio for a period of time ... across a succession of instantaneous audio samples. Audio can be thought of as a time series curve where for each instant in time you record the height of the audio curve digitized into PCM format. It takes wall clock time to hear a given "major sound". Here your audio is in its natural state in the time domain. However the information load of a stretch of audio can be transformed into its frequency domain counterpart by feeding a window of audio samples into a fft api call ( to take its Fourier Transform ).
A powerfully subtle aspect of taking the FFT is it removes the dimension of time from the input data and replaces it with a distillation while retaining the input information load. As an aside, if the audio is periodic once transformed from the time domain into its frequency domain representation by applying a Fourier Transform, it can be reconstituted back into the same identical time domain audio curve by applying an inverse Fourier Transform. The data which began life as a curve which wobbles up and down over time is now cast as a spread of frequencies each with an intensity and phase offset yet critically without any notion of time. Now you have the luxury to pluck from this static array of frequencies a set of attributes which can be represented by a mundane struct data structure and yet imbued by its underlying temporal origins.
Here is where you can find your "major sounds". To a first approximation you simply stow the top X frequencies along with their intensity values and this is a measure of a given stretch of time of your input audio captured as its "major sound". Once you have a collection of "major sounds" you can use this to identify when any subsequent audio contains an occurrence of a "major sound" by performing a difference match test between your pre stored set of "major sounds" and the FFT of the current window of audio samples. You have found a match when there is little or no difference between the frequency intensity values of each of those top X frequencies of the current FFT result compared against each pre stored "major sound"
I could digress by explaining how by sitting down and playing the piano you are performing the inverse Fourier Transform of those little white and black frequency keys, or by saying the muddied wagon tracks across a spring rain swollen pasture is the Fourier Transform of all those untold numbers of heavily laden market wagons as they trundle forward leaving behind an ever deepening track imprinted with each wagon's axle width, but I won't.
Here are some links to audio fingerprinting
Audio fingerprinting and recognition in Python
https://github.com/worldveil/dejavu
Audio Fingerprinting with Python and Numpy http://willdrevo.com/fingerprinting-and-audio-recognition-with-python/
Shazam-like acoustic fingerprinting of continuous audio streams (github.com) https://news.ycombinator.com/item?id=15809291
https://github.com/dest4/stream-audio-fingerprint
Audio landmark fingerprinting as a Node Stream module - nodejs converts a PCM audio signal into a series of audio fingerprints. https://github.com/adblockradio/stream-audio-fingerprint
https://stackoverflow.com/questions/26357841/audio-matching-audio-fingerprinting