Writing an audio file

1 回表示 (過去 30 日間)
Yanjika O
Yanjika O 2020 年 6 月 26 日
コメント済み: Yanjika O 2020 年 6 月 26 日
Dear people,
I am trying to write an audio which consists of part of 2500Hz 17 sec long and another silent part of 1 min in length.
FrequencySampling = 2500;
duration = 17;
repeats=5;
filename='shock.wav';
t = linspace(0, duration, FrequencySampling*duration+1);
t(end) = [];
w = 2*pi*1000;
for i=1:repeats
for k=1:duration
s = sin(w*t);
sound(s,FrequencySampling);
end
pause(77);
end
audioWrite(filename,s,FrequencySampling);
When I use this code I am only able to write it for single 17 sec long 2500Hz tone. I want to inlcude 4 silent periods between 5 repeats of 17 sec long 2500Hz tone. How to do it? Please suggest.

回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 6 月 26 日
FrequencySampling = 2500;
duration = 17;
repeats = 5;
filename='shock.wav';
s = cell(2, repeats);
t = linspace(0, duration, FrequencySampling*duration+1);
t(end) = [];
w = 2*pi*1000;
n = sin(w*t);
z = zeros(1, 77*FrequencySampling);
s(1,:) = {n};
s(2,:) = {z};
s(end) = []; %delete final silence
s = horzcat(s{:});
audioWrite(filename, s, FrequencySampling);
Repeating for duration is not needed, as your time vector already extends for the entire duration.
  1 件のコメント
Yanjika O
Yanjika O 2020 年 6 月 26 日
IDK why but I a getting this error tho,
Cannot find an exact (case-sensitive) match for
'audioWrite'

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

カテゴリ

Help Center および File ExchangeAudio and Video Data についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by