Processing audio files that are browsed from a computer directory
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Winda Mariana
le 20 Mar 2021
Commenté : Walter Roberson
le 21 Mar 2021
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.
0 commentaires
Réponse acceptée
Walter Roberson
le 20 Mar 2021
Modifié(e) : Walter Roberson
le 20 Mar 2021
[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 commentaires
Walter Roberson
le 21 Mar 2021
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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur AI for Audio dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!