Is there a way to load and play .wav files? This is what I have:
s = 'diglett.wav';
Fs = 8000;
audiowrite(s,y,Fs);
clear y Fs
[y, Fs] = audioread('diglett.wav');
soundsc(y,Fs);
But I know this is wrong. I really need it to xcorr with recorded audio from mic and I don't know if this is even the right way to do it.

 Réponse acceptée

Walter Roberson
Walter Roberson le 24 Nov 2017

0 votes

4 commentaires

NOR AZIEYANI
NOR AZIEYANI le 14 Déc 2018
Is there a way to load and play .wav files? I got this code but the .wav files cannot play the sound.
myFileName = 'abang.wav';
myDirectory = 'C:\R2013a\bin\Recordings\abang.wav';
filepath = fullfile(myFileName, myDirectory);
if exist(filepath,'file') ==2;
[y,Fs] = audioread('abang.wav', string);
load abang;
sound(y,Fs);
load abang.wav
playerObj = audioplayer(y,Fs);
start = playerObj.SampleRate *4;
play(playerObj,start);
end
Walter Roberson
Walter Roberson le 14 Déc 2018
Modifié(e) : Walter Roberson le 14 Déc 2018
myDirectory = 'C:\R2013a\bin\Recordings';
You cannot load a .wav though.
And what is string in your code? It would have to be either 'double' or 'native' or a vector of two numeric values for that code to work.
NOR AZIEYANI
NOR AZIEYANI le 14 Déc 2018
Okay, my bad.Actually, I am writing a Malay language text to speech program.Its very simple; it reads the string from the .txt file,scan it and then matches it in the database, and plays the wave file that match of the string . The database holds the .wav files of word, e.g. the word "saya" has a corresponding file saya.wav in the database. I know this code is wrong because it cannot play the wav file. Can you help me. So far my code is:
%scan text from file
fid = fopen('saya_1.txt');
C = textscan(fid,'%s %s %f32 %d8 %u %f %f %s %f');
fclose(fid);
%connection to SQLite database
javaaddpath('C:\Users\user\AppData\Roaming\MathWorks\MATLAB\R2013a\sqlite-jdbc-3.8.11.2.jar');
dbpath =('C:\Users\user\Desktop\db\tts.db');
datasource = 'tts';
user = '';
password = '';
driver = 'org.sqlite.JDBC';
protocol = 'jdbc';
subprotocol = 'sqlite';
resource = dbpath;
url = strjoin({protocol, subprotocol, resource}, ':');
conn = database(dbpath, user, password, driver, url);
%match string to database
query = 'SELECT *FROM MALAY';
cursor = exec(conn, query);
cursor = fetch(cursor);
result = cursor.Data;
%match string from scan to database
str = {'C'};
expression = '\w+';
matchStr = regexp(str, expression,'match');
%match the string with voice recording
wavdirectory = 'C:\R2013a\bin\Recordings';
[~, number_of_words] = size(matchStr); %stores number of words in user
% input string
for m = 1:number_of_words
filename = [wavdirectory matchStr{m} '.wav'];
if(exist(filename, 'file') ~= 0)
[y, fs] = audioread(filename);
sound(y, fs);
else
fprintf('Word %s does not exist', wordsstring{m});
end
end
Walter Roberson
Walter Roberson le 17 Déc 2018
filename = fullfile(wavdirectory, [matchStr{m} '.wav']);

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Audio I/O and Waveform Generation dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by