音声ファイルの無作為抽出について

2 Ansichten (letzte 30 Tage)
Kiki
Kiki am 16 Sep. 2020
Beantwortet: Atsushi Ohashi am 17 Sep. 2020
音声ファイルの無作為抽出方法を教えてください。
例えば、「001.wav」「002.wav」「003.wav」の音声ファイルがあったとして、
これらからランダムに1つのファイルを選択・再生をするプログラム方法を知りたいです。

Akzeptierte Antwort

Atsushi Ohashi
Atsushi Ohashi am 17 Sep. 2020
音声ファイル名を1つのセル配列にまとめ、randi 関数を使ってインデックスを求める方法がございます。
% ファイルをセル配列に格納
cellFiles = {'001.wav', '002.wav', '003.wav'};
% ランダムなインデックス値を取得
idx = randi( numel(cellFiles), 1 );
% インデックス値からファイル名を取得
filename = cellFiles{idx};
% 音声再生
[y, Fs] = audioread( filename);
sound(y, Fs);

Weitere Antworten (0)

Kategorien

Mehr zu Audio I/O and Waveform Generation finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!