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

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

 Accepted Answer

Atsushi Ohashi
Atsushi Ohashi on 17 Sep 2020

0 votes

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

More Answers (0)

Categories

Find more on Audio I/O and Waveform Generation in Help Center and File Exchange

Products

Release

R2020a

Community Treasure Hunt

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

Start Hunting!