Processing audio files that are browsed from a computer directory

2 ビュー (過去 30 日間)
Winda Mariana
Winda Mariana 2021 年 3 月 20 日
コメント済み: Walter Roberson 2021 年 3 月 21 日
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.

採用された回答

Walter Roberson
Walter Roberson 2021 年 3 月 20 日
編集済み: Walter Roberson 2021 年 3 月 20 日
[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 件のコメント
Walter Roberson
Walter Roberson 2021 年 3 月 21 日
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.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by