Convert csv file to .wav file with same file name

15 ビュー (過去 30 日間)
Giggs B.
Giggs B. 2022 年 3 月 16 日
コメント済み: Walter Roberson 2023 年 9 月 2 日
Hi,
I think this would be very simple, but I am unable to pass the csv file name to my .wav file. My plan is to read a csv file, cconvert it into a wav file and store it in another folder with the same file name as csv. But I am unable to pass the filename. In my code, inside 'audiowrite()' I provided 'name' thinking that this 'name' will be taken from the 'fileparts()' function, instead it just creates a new file with name as 'name.wav'!
I know the path I provided is a "fixed CHAR vector" so it can't actually get the actual name of the csv file. Then how can I do this? Thanks.
files = dir('*.csv');
for file = files'
n = readmatrix(file.name);
[filepath,name,ext] = fileparts(file.name);
m = rescale(n, -1, 1, 'InputMin',2301,'InputMax',3642)+0.527;
audiowrite('C:\Users\gagan\Downloads\testing_lab\sound files\name.wav',m,40000,'BitsPerSample',16);
clearvars
end
  2 件のコメント
RAGHUNATH
RAGHUNATH 2023 年 9 月 2 日
How to convert exsl(.csv) file to wav file
Walter Roberson
Walter Roberson 2023 年 9 月 2 日
My code in my Answer shows converting a directory of csv files to corresponding wav files, under the assumption of particular minimum and maximums and particular recording rate.
The difference for xls or xlsx files would just be changing the '*.csv' to the appropriate file extension.
The input minimums and maximums and the sample rate would have to be adjusted for your situation.

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

採用された回答

Walter Roberson
Walter Roberson 2022 年 3 月 16 日
indir = '.'; %were are the csv? %current directory
outdir = 'C:\Users\gagan\Downloads\testing_lab\sound files'; %where to write the results
files = dir( fullfile(indir, '*.csv'));
for file = files'
inname = fullfile(file.folder, file.name);
n = readmatrix(inname);
m = rescale(n, -1, 1, 'InputMin',2301,'InputMax',3642)+0.527;
[filepath,name,ext] = fileparts(inname);
outname = fullfile(outdir, name + ".wav");
audiowrite(outname, m, 40000, 'BitsPerSample', 16);
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by