MATLAB Answers

[Concatenating .wav files on the base of the values specified in a separate matrix.

2 ビュー (過去 30 日間)
elio germano
elio germano 2019 年 11 月 28 日
回答済み: Divya Gaddipati 2020 年 1 月 6 日
I have several .wav files in a folder and I need to join them following the values specified in the columns of a matrix. This is a example of the matrix:
ID FileName Trial
1 p8-cut_1 1
1 p8-cut_2 1
1 p8-cut_3 1
1 p8-cut_4 1
1 p8-cut_5 2
1 p8-cut_6 2
2 p9-cut_1 1
2 p9-cut_2 1
2 p9-cut_3 2
And so on. Now I would need to join together the files with the same values on both ID and Trial columns (e.g the the first four files, than the next two, and so on...). Is there a way to do that? I didn't find nothing similar in previous threads.......

  2 件のコメント

Divya Gaddipati
Divya Gaddipati 2019 年 12 月 4 日
Can you elaborate which files you want to combine in the example that you have given?
The way I understand it is, you'll get two different files by combining in the following way
  • p8-cut_1, p8-cut_2, p8-cut_3, p8-cut_4
  • p9-cut_3
And discard the p8-cut_5, p8-cut_6, p9-cut_1, p9-cut_2 as ID and Trial of these are not same.
Is that right?
elio germano
elio germano 2019 年 12 月 5 日
This is only a subset of my matrix, in fact the audio files are more than one thousand. To better explain the criteria by which I want to merge the audio files:
  • Filename: column indicating the .wav filename in my folder
  • ID: identification code of each subject (so all the audio files with ID1 belong to the same people)
  • Trial: Each trial of the task the subject performed. So, all the audio files with TRIAL1 belong to the first trial of the task that subject performed)
Now, the .wav files have been cleaned to remove additional voice and noise (except that of the subject), and divided into different cuts. Now, for each ID (i.e. for each subject) I want to merge again together the cuts belonging to the same trials. So, in this case:
  • p8-cut_1, p8-cut_2, p8-cut_3, p8-cut_4 : merge these together in a separated .wav
  • p8-cut_5, p8-cut_6: merge these together in another separated .wav
  • p9-cut_1, p9-cut_2: merge these together in even another separated .wav
and so on, considering that in my folder I have more ore less 2000 .wav....

サインイン to comment.

回答 (1 件)

Divya Gaddipati
Divya Gaddipati 2020 年 1 月 6 日
You can concatenate wav files in the following way:
y_concat = [y1; y2];
As for checking if ID and Trial are same for the files, you would have to loop through all the files. Rough steps are provided below:
  • Store the IDs and Trials in two variables, ID and Trial for example.
  • Create an empty cell matrix where you want to store the concatenated wav files.
y_concat = {};
for i = 1 : length(num_files) % num_files = total number of files
[y1, Fs] = audioread(filename{i});
y_concat{ID(i), Trial(i)} = [y_concat{ID(i); Trial(i)}; y1];
Hope this helps!

  0 件のコメント

サインイン to comment.

サインイン してこの質問に回答します。

Translated by