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

音声ファイルの無作為抽出方法を教えてください。
例えば、「001.wav」「002.wav」「003.wav」の音声ファイルがあったとして、
これらからランダムに1つのファイルを選択・再生をするプログラム方法を知りたいです。

 Akzeptierte Antwort

Atsushi Ohashi
Atsushi Ohashi am 17 Sep. 2020

0 Stimmen

音声ファイル名を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 Hilfe-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!