What is pitch in a wav file? How to create a pitch.m file from a wav.m file?
MATLAB: Signal processing and speech recognition
speech recognition
Related Solutions
You can get a directory and then use randperm to get a list of random, non-repeated indexes, or randi to get a list of possibly repeated indexes, or you can use this program I wrote that will play either a random wave file or one that you specify:
% Play a wav file. You can pass in 'random' and it will pick one at random from the folder to play.
% PlaySoundFile(handles.soundFolder, 'chime.wav');
% PlaySoundFile(handles.soundFolder, 'random');
function PlaySoundFile(soundFolder, baseWavFileName) try % Read the sound file into MATLAB, and play the audio.
% soundFolder = fullfile(soundFolder, 'Sound Files');
if ~exist(soundFolder, 'dir') warningMessage = sprintf('Warning: sound folder not found:\n%s', soundFolder); WarnUser(warningMessage); return; end if strcmpi(baseWavFileName, 'random') itWorked = false; tryCount = 1; while itWorked == false % Pick a file at random.
filePattern = fullfile(soundFolder, '*.wav'); waveFiles = dir(filePattern); numberOfFiles = length(waveFiles); % Get a random number
fileToPlay = randi(numberOfFiles, 1); baseWavFileName = waveFiles(fileToPlay).name; fullWavFileName = fullfile(soundFolder, baseWavFileName); waveFileData = -1; try if exist(fullWavFileName, 'file') [waveFileData, Fs, nbits, readinfo] = wavread(fullWavFileName); sound(waveFileData, Fs); % soundsc(y,Fs,bits,range);
else warningMessage = sprintf('Warning: sound file not found:\n%s', fullWavFileName); WarnUser(warningMessage); end % It worked. It played because the audio format was OK.
itWorked = true; catch % Increment the try count and try again to find a file that plays.
tryCount = tryCount + 1; if tryCount >= numberOfFiles break; end end end % of while()
else % baseWavFileName = 'Chime.wav';
fullWavFileName = fullfile(soundFolder, baseWavFileName); waveFileData = -1; if exist(fullWavFileName, 'file') [waveFileData, Fs, nbits, readinfo] = wavread(fullWavFileName); sound(waveFileData, Fs); % soundsc(y,Fs,bits,range); else warningMessage = sprintf('Warning: sound file not found:\n%s', fullWavFileName); WarnUser(warningMessage); end end catch ME if strfind(ME.message, '#85') % Unrecognized format. Play chime instead.
fprintf('Error in PlaySoundFile(): %s.\nUnrecognized sound format in file:\n\n%s\n', ME.message, fullWavFileName); baseWavFileName = 'Chime.wav'; fullWavFileName = fullfile(soundFolder, baseWavFileName); waveFileData = -1; if exist(fullWavFileName, 'file') [waveFileData, Fs, nbits, readinfo] = wavread(fullWavFileName); sound(waveFileData, Fs); % soundsc(y,Fs,bits,range); end end errorMessage = sprintf('Error in PlaySoundFile().\nThe error reported by MATLAB is:\n\n%s', ME.message); fprintf('%s\n', errorMessage); WarnUser(errorMessage); end return; % from PlaySoundFile
By the way, WarnUser is simply
function WarnUser(message)uiwait(warndlg(message));
In Section 5 ‘Materials and Methods’, the authors note: ‘... pied butcherbird singing performances were digitally recorded at a sample rate of 44.1 kHz and 16 bits ...’
With that added bit of information, you can hear them in their full glory, for example:
d = load('Audio_Bird1.mat');Bird1 = d.Audio_Bird1;Fs = 44.1E+3; % Sampling Frequency
nBits = 16; % Bit Resolution
Audio_Bird1 = audioplayer(Bird1, Fs, nBits); % Create ‘audioplayer’ Object
audiowrite('Audio_Bird1.wav', Bird1, Fs, 'BitsPerSample',nBits, 'Comment','Australian pied butcherbird song - Bird1');play(Audio_Bird1) % Play Song
EDIT — Added sudiowrite call to save as .wav file.
Best Answer