Processing audio files that are browsed from a computer directory

3 ビュー (過去 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 件のコメント
Winda Mariana
Winda Mariana 2021 年 3 月 21 日
編集済み: Walter Roberson 2021 年 3 月 21 日
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
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 件)

カテゴリ

Help Center および File ExchangeHamming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by