Processing audio files that are browsed from a computer directory

I want to do watermarking to an audio that is browsed via the 'Browse' button.
Here is my code to browse audio files from my computer:
% button to browse audio file from computer directory
[filename, pathname] = uigetfile ({'*. wav'}, 'Select File');
fullpathname = strcat (pathname, filename);
[data] = audioread (fullpathname);
plot (data);
and on another button, namely the 'Embedding' button, which will embed the watermark for the audio that has been browsed.
Here's my code:
audioFile = char (strcat (pathname, filename));
[data, Fs] = audioread (audioFile);
sr = 44100; % sampling rate
w = 512; % window size
T = w / sr; % period
t = linspace (0, 1, 44100);
twindow = t (1: 512);
hamming = 0.54 - 0.46 * cos ((2 * pi * twindow) / T);
plot (hamming);
But I get an error when I want to process the audio file that has been browsed. I hope someone can help me.

 Risposta accettata

[filename, pathname] = uigetfile ({'*. wav'}, 'Select File');
fullpathname = strcat (pathname, filename);
Do not use strcat() between directories and file like that. uigetfile() does not promise that it will leave a directory separator at the end of the pathname . Use fullfile() instead. Also, check to see whether the user cancelled
if ~ischar(filename)
return; %user cancel
end
fullpathname = fullfile(pathname, filename);

8 Commenti

how about this code sir, i want to do I want to Hamming window to the audio file that has been browsed
audioFile = char (strcat (pathname, filename));
[data, Fs] = audioread (audioFile);
sr = 44100; % sampling rate
w = 512; % window size
T = w / sr; % period
t = linspace (0, 1, 44100);
audioFile = fullfile(pathname, filename);
question:
sr = 44100; % sampling rate
Why are you ignoring the sample rate that you read from the file, Fs?
Why are you constructing t for one second at your assumed sample rate instead of taking (1:length(data))/Fs for the times?
I want to process audio file that have been browsed from button "Browse" sir and i make a code like this to do Hamming window:
audioFile = fullfile(pathname, filename);
[data,Fs] = audioread(audioFile);
sr = 44100; %sampling rate
w = 512; %window size
T = w/sr; %period
% t is an array of times at which the hamming function is evaluated
t = linspace(0, 1, 44100);
twindow = t(1:512);
hamming = 0.54 - 0.46 * cos((2 * pi * twindow)/T);
plot(hamming);
but i get an error, please help me
What is the error message?
You did not answer my questions about 44100 and about t
abaout 44100 and t are the sample sir, so its just a example
for the first, i am browse the audio file by button "Browse"
and this the code for button "Browse":
[filename, pathname] = uigetfile({'*.wav'}, 'Select File');
fullpathname = fullfile (pathname, filename);
[data,fs] = audioread(fullpathname);
%show the plot audio
plot(data)
and when i click button "Embed", i want to do hamming window with the audio that have been browsed by button "Browse" sir
and this the code for button "Embed":
audioFile = fullfile(pathname, filename);
[data,Fs] = audioread(audioFile);
sr = 44100; %sampling rate
w = 512; %window size
T = w/sr; %period
% t is an array of times at which the hamming function is evaluated
t = linspace(0, 1, 44100);
twindow = t(1:512);
hamming = 0.54 - 0.46 * cos((2 * pi * twindow)/T);
plot(hamming);
but, there is an error in matlab sir, I hope you can check my code where it went wrong. Thank you
audioFile = fullfile(pathname, filename);
[data,sr] = audioread(audioFile);
w = 512; %window size
T = w/sr; %period
% t is an array of times at which the hamming function is evaluated
twindow = (0:w-1)/sr;
hamming = 0.54 - 0.46 * cos((2 * pi * twindow)/T);
plot(hamming);
To get any further than this, you will need to show me the error message instead of just saying that some error is occurring.
and this the code for button "Embed"
Where are you getting pathname and filename for that button? You do not have a uigetfile() call in that button. Are you assuming that just because you assigned to pathname and filename in some other function that the variables will be defined here? They will not be: each function has its own workspace and that workspace disappears when the function returns.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Simulation, Tuning, and Visualization in Centro assistenza e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by