Convert csv file to .wav file with same file name

47 visualizaciones (últimos 30 días)
Giggs B.
Giggs B. el 16 de Mzo. de 2022
Comentada: Walter Roberson el 2 de Sept. de 2023
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 comentarios
RAGHUNATH
RAGHUNATH el 2 de Sept. de 2023
How to convert exsl(.csv) file to wav file
Walter Roberson
Walter Roberson el 2 de Sept. de 2023
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.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 16 de Mzo. de 2022
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

Más respuestas (0)

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by