How to get the audioread.m file again in the matlab? - matlab

I have edited the audioread.m file
I have used
which('audioread', '-all')
rmpath(fileparts(which('audioread')))
savepath
Now I have got an error
Undefined function or variable 'audioread'.
I have checked with
[d,sr] = audioread('sadness22.wav');
% Plot the spectrogram
subplot(311)
specgram(d(:,1),1024,sr);
% Read in a different format
[d2,sr] = audioread('piano.mp3');
subplot(312)
specgram(d2(:,1),1024,sr);
Can you please give any suggestions regarding this issue?

Related

MATLAB code for combining .fig files from a folder to generate a video/ animation?

I am trying to make an animation from a sequence of figures (.fig) files of MATLAB from a folder in my system. I referred to the questions here and here.
Finally, I have the code mkvideo.m :
% Creating Video Writer Object
writerObj = VideoWriter('peqr.avi');
% Using the 'Open` method to open the file
open(writerObj);
% Creating a figure.
% Each frame will be a figure data
Z = peqr;
surf(Z);
axis tight
set(gca,'nextplot','replacechildren');
set(gcf,'Renderer','zbuffer');
[figures,var] = uigetfile('*.fig','Multiselect','on');
for k = 1:length(figures)
Multi_Figs = [var,filesep,figures{k}];
Op = openfig(Multi_Figs);
% Frame includes image data
frame = getframe;
% Adding the frame to the video object using the 'writeVideo' method
writeVideo(writerObj,frame);
close(Op);
end
% Closing the file and the object using the 'Close' method
close(writerObj);
I am getting the following error
Warning: No video frames were written to this file. The file may be invalid.
> In VideoWriter/close (line 278)
In VideoWriter/delete (line 213)
In mkvideo (line 2)
Undefined function or variable 'peqr'.
Error in mkvideo (line 8)
Z = peqr;
I think this code should be able to produce a video once in user interface, I select the files?
It would be helpful if I could get some help to rectify the error in this code so that the animation or video making is possible.

Undefined function or variable 'mmreader'

I try to use matlab 2016a to read avi videos, however, I get the following problems:
undefined funciton or variable 'mmreader';
The code is as following:
clc;
clear;
%% this to read avi by using mmread to get every frame
video = mmreader('D:\My Documents\MATLAB\My\fire.avi');
nFrames = video.NumberOfFrames;
H = video.Height;
W = video.Width;
Rate = video.FrameRate;
% Preallocate movie structure.
mov(1:nFrames) = struct('cdata',zeros(H,W,3,'uint8'),'colormap',[]);
%read one frame every time
for i = 1:nFrames
mov(i).cdata = read(video,i);
P = mov(i).cdata;
disp('current frame number:'),disp(i);
imshow(P),title('original picture');
% P2=rgb2gray(P);
end
Why? Could anyone help me? Thanks in advance.
The function mmreader was deprecated in version R2010b, removed in version R2014a, and removed from the documentation altogether in version R2015b. It was replaced by the VideoReader function, so use that in its place.

Matlab error when playing a sound

I'm using matlab gui, I'm recording a sound then save it in a folder in c, then display the recorded sound that are in the folder in a listbox when I press play on the sound wav. Matlab gives an error the error is :
************Error using audioread (line 74)**
***The filename specified was not found in the MATLAB path.
Error in Monitoring_System>play_Callback (line 178)
[q, Fs] = audioread(thisstring);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in Monitoring_System (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in #(hObject,eventdata)Monitoring_System('play_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback*************
-The record code:
format shortg
c = clock;
fix(c);
a=num2str(c);
year=strcat(a(1),a(2),a(3),a(4),a(5));
month=strcat(a(19),a(20));
day=strcat(a(33),a(34));
hour=strcat(a(48),a(49));
min=strcat(a(63),a(64));
sec=strcat(a(74),a(75));
name=strcat(year,'-',month,'-',day,'-',hour,'-',min,'-',sec);
fullpath=fullfile('c:\monitoringsystem',name);
wavwrite(y,44100,fullpath);
y=[];
The code to diplay them in the listbox:
d = dir('C:\monitoringsystem\*.wav'); %get files
set(handles.listbox1,'String',{d.name})
The code to play the sound that is chosen from the listbox:
allstrings = cellstr( get(handles.listbox1, 'String') );
curvalue = get(handles.listbox1, 'Value');
thisstring = allstrings{curvalue};
[q, Fs] = audioread(thisstring);
soundsc(q,44100);
Any help how to solve this problem, with keeping to save in a specific folder. I copied the recorded sound to the matlab folder and then pressed play in the gui for that wav sound it didin't give any error.
Did you try debugging this and seeing what d contains after selecting a file?
As per the documentation, d = dir('C:\monitoringsystem\*.wav'); returns a struct with the following fields: name, date,bytes, isdir, datenum (at least on MATLAB 2015a). Although {d.name} gives you the filename correctly, you should note that this is a relative path only, so MATLAB doesn't where to look for the file unless it's in the active directory.
I'm not entirely sure why you went through all the trouble with allstrings, curvalue, and thisstring, but if I understand correctly what you're trying to do, I would suggest one of two approaches:
Define the default path (i.e. C:\monitoringsystem) in a constant, and then use it when saving\loading:
DEFAULT_PATH = `C:\monitoringsystem`; %// Definition
...
fullpath = fullfile(DEFAULT_PATH,name); %// When saving
...
d = dir(fullfile(DEFAULT_PATH,'*.wav')); %// When listing files
...
[q, Fs] = audioread(fullfile(DEFAULT_PATH,{d.name})); %// When reading a file
Using uigetfile:
[FileName,PathName] = uigetfile('*.wav','Select the WAV file');
FullPath = fullfile(PathName,FileName);
(and then the rest is very similar to the 1st case)

How to save multiple file (.mat) into .wav using MATLAB

I have a .mat file containing 100files. How to convert the 100 files one by one to .wav.
Every file contain vectors.I tried using this code but I got errors.
x=load('data_cropped.mat');
input_list = x;
for i = 1:length(input_list)
fid = fopen(input_list(i).name);
data = ' ';
fopen(fid);
wavwrite(data,16000,[input_list(i).name(1:length(input_list(i).name)-3),'wav']);
clear data
end
The error is:
>> convert_to_wav
Reference to non-existent field 'name'.
Error in convert_to_wav (line 7)
fid = fopen(input_list(i).name);
Please help me,
Thanks a lot
Assuming you know the sample rate of your audio then the snippet below should do what you want and give you a series of numbered wav files.
clear
load('data_cropped.mat');
data = whos;
fs = 44100 %change to your sample rate
for i = 1:length(data)
wavwrite(data(i).name,fs,num2str(i));
end

FSEEK error while running Matlab function

I got this error while running a function in Matlab
"Error using fseek Invalid file identifier. Use fopen to generate a valid file identifier."
May I know what is the possible causes of this error? I am very new to Matlab. Please help me. Thanks a lot
I am sorry if I should not post the overall function. But I am afraid the information I gave is not enough. The overall command of the function is:
function gau_hmm_init_train(traininglist_filename,model_filename,MODEL_NO,STATE_NO, dim )
if nargin == 0
traininglist_filename='training_list.mat' ;
model_filename='models.mat';
MODEL_NO=11;
STATE_NO=4;
dim=12;
end
MIN_SELF_TRANSITION_COUNT=0;
load(traininglist_filename,'list');
% allocate mean, var vectors, transition prob. for the of models
mean_vec_i_m=zeros(dim,STATE_NO,MODEL_NO);
var_vec_i_m=zeros(dim,STATE_NO,MODEL_NO);
A_i_m=zeros(STATE_NO,MODEL_NO);
vector_sums_i_m=zeros(dim,STATE_NO,MODEL_NO);
var_vec_sums_i_m=zeros(dim,STATE_NO,MODEL_NO);
fr_no_i_m=zeros(STATE_NO,MODEL_NO);
self_tr_fr_no_i_m=zeros(STATE_NO,MODEL_NO);
utterance_no=size(list,1);
total_fr_no=0;
for k=1:utterance_no
filename=list{k,2};
m=list{k,1}; % word ID
fid=fopen(filename,'r');
fseek(fid, 12, 'bof'); % skip the 12-byte HTK header
%fopen(fid, 12, 'bof'); % skip the 12-byte HTK header
c=fread(fid,'float','b');
fclose(fid);
fr_no=length(c)/dim;
total_fr_no=total_fr_no+fr_no;
c=reshape(c,dim,fr_no);
for i=1:STATE_NO
begin_fr=round( fr_no*(i-1) /STATE_NO)+1;
end_fr=round( fr_no*i /STATE_NO);
seg_length=end_fr-begin_fr+1;
vector_sums_i_m(:,i,m) = vector_sums_i_m(:,i,m) + sum(c(:,begin_fr:end_fr),2);
var_vec_sums_i_m(:,i,m) = var_vec_sums_i_m(:,i,m) + sum( c(:,begin_fr:end_fr).*c(:,begin_fr:end_fr) , 2);
fr_no_i_m(i,m)=fr_no_i_m(i,m)+seg_length;
self_tr_fr_no_i_m(i,m)= self_tr_fr_no_i_m(i,m) + seg_length-1;
end %for s=1:STATE_NO
end % for k=1:utterance_no
for m=1:MODEL_NO
for i=1:STATE_NO
mean_vec_i_m(:,i,m) = vector_sums_i_m(:,i,m) / fr_no_i_m(i,m);
var_vec_i_m(:,i,m) = var_vec_sums_i_m(:,i,m) / fr_no_i_m(i,m);
A_i_m(i,m)=(self_tr_fr_no_i_m(i,m)+MIN_SELF_TRANSITION_COUNT)/(fr_no_i_m(i,m)+2*MIN_SELF_TRANSITION_COUNT);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% tying of cov. matrices
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
overall_var_vec=sum(sum(var_vec_sums_i_m(:,:,:),3 ),2)/sum(sum(fr_no_i_m,2 ),1);
for m=1:MODEL_NO
for i=1:STATE_NO
var_vec_i_m(:,i,m)=overall_var_vec;
end
end
%%%%%%%%%%%%%%%% end of cov. matrices tying
save(model_filename, 'mean_vec_i_m', 'var_vec_i_m', 'A_i_m');
fprintf('init. train complete \n');***
Sounds like the line fid=fopen(filename, 'r'). This filename comes from the list variable which is loaded from the file traininglist_filename, so you should check that these files exist. If you're passing it a traininglist_filename you should load this file in MATLAB and look at the contents of list; otherwise it will load the default 'training_list.mat', so you should look in there to make sure all the filenames are valid. Perhaps you're missing a file?
To continue the reply by #Wakjah, the training_list.mat file is missing from the reference path by the code you are using because it is automatically created at MATLAB default path. Therefore, just change the path at the 'Current Folder' to where you had open your current code and it should work.