Anurag Pujari asked . 2024-03-09

signal processing and speech recognition

What is pitch in a wav file? How to create a pitch.m file from a wav.m file?
 

speech recognition , Audio Processing Algorithm Design , Signal Processing

Expert Answer

Prashant Kumar answered . 2024-12-21 15:49:21

Here's a little demo where I created a wave file using mathematical functions to vary the pitch and amplitude. Play around with the settings and see how the sound and appearance of the waveform are affected. Save the code as make_wav_file.m and run it.

 
 
% Program to create a wave file with variable amplitude and pitch.
function make_wav_file()
% Initialization / clean-up code.
clc;    % Clear the command window.
close all;  % Close all figures (except those of imtool.)
clear;  % Erase all existing variables. Or clearvars if you want.
workspace;  % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;

% Create the filename where we will save the waveform.
folder = pwd;
baseFileName = 'Test_Wave.wav';
fullFileName = fullfile(folder, baseFileName);
fprintf('Full File Name = %s\n', fullFileName);

% Set up the time axis:
t = 1:15000;

% Set up the period (pitch, frequency):
T = 13;
T = linspace(25, 8, length(t)); % Pitch changes.

% Create the maximum amplitude:
Amplitude = 32767;
% Add an exponential decay:
Amplitude = Amplitude .* exp(-0.0003*t);

% Add an ocillation on the amplitude:
% Amplitude = Amplitude .* rand(1, length(x)); % Makes a shushing/roaring sound.
Amplitude = Amplitude .* sin(2.*pi.*t./2000); % Decaying pulsing sound.

% Construct the waveform:
y = int16(Amplitude .* sin(2.*pi.*t./T));
% y = abs(int16(Amplitude .* sin(2.*pi.*x./T)));

% Plot the waveform:
plot(t, y, 'b-');
title('Waveform', 'FontSize', fontSize);
xlabel('Time', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
grid on;
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
fprintf('Writing file %s...\n', fullFileName);

% Write the waveform to a file:
wavwrite(y, fullFileName);

% Play the sound as many times as the user wants.
playAgain = true;
counter = 1;
while playAgain
  % Play the sound that we just created.
  fprintf('Playing file %s   %d times...\n', fullFileName, counter);
  PlaySoundFile(folder, baseFileName);
  % Ask user if they want to play the sound again.
  promptMessage = sprintf('You have played the sound %d times.\nDo you want to play the sound again?', counter);
  titleBarCaption = 'Continue?';
  button = questdlg(promptMessage, titleBarCaption, 'Yes', 'No', 'Yes');
  if strcmpi(button, 'No')
    playAgain = false;
    break;
  end
  counter = counter + 1;
end

% Alert user that we are done.
message = sprintf('Done playing %s.\n', fullFileName);
fprintf('%s\n', message);
promptMessage = sprintf('Done playing %s.\nClick OK to close the window\nor Cancel to leave it up.', fullFileName);
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'OK', 'Cancel', 'OK');
if strcmpi(button, 'OK')
  close all;  % Close down the figure.
end

%================================================================================================
% 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)
  global waveFileData;
  global Fs;  % Wave file information.
  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

 


Not satisfied with the answer ?? ASK NOW

Frequently Asked Questions

MATLAB offers tools for real-time AI applications, including Simulink for modeling and simulation. It can be used for developing algorithms and control systems for autonomous vehicles, robots, and other real-time AI systems.

MATLAB Online™ provides access to MATLAB® from your web browser. With MATLAB Online, your files are stored on MATLAB Drive™ and are available wherever you go. MATLAB Drive Connector synchronizes your files between your computers and MATLAB Online, providing offline access and eliminating the need to manually upload or download files. You can also run your files from the convenience of your smartphone or tablet by connecting to MathWorks® Cloud through the MATLAB Mobile™ app.

Yes, MATLAB provides tools and frameworks for deep learning, including the Deep Learning Toolbox. You can use MATLAB for tasks like building and training neural networks, image classification, and natural language processing.

MATLAB and Python are both popular choices for AI development. MATLAB is known for its ease of use in mathematical computations and its extensive toolbox for AI and machine learning. Python, on the other hand, has a vast ecosystem of libraries like TensorFlow and PyTorch. The choice depends on your preferences and project requirements.

You can find support, discussion forums, and a community of MATLAB users on the MATLAB website, Matlansolutions forums, and other AI-related online communities. Remember that MATLAB's capabilities in AI and machine learning continue to evolve, so staying updated with the latest features and resources is essential for effective AI development using MATLAB.

Without any hesitation the answer to this question is NO. The service we offer is 100% legal, legitimate and won't make you a cheater. Read and discover exactly what an essay writing service is and how when used correctly, is a valuable teaching aid and no more akin to cheating than a tutor's 'model essay' or the many published essay guides available from your local book shop. You should use the work as a reference and should not hand over the exact copy of it.

Matlabsolutions.com provides guaranteed satisfaction with a commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been empanelled after extensive research and quality check.

Matlabsolutions.com provides undivided attention to each Matlab assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work done at the best price in industry.