How to play .wav

조회 수: 69 (최근 30일)
Nathaniel Sweeney
Nathaniel Sweeney 2017년 11월 24일
댓글: Walter Roberson 2018년 12월 17일
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.

채택된 답변

Walter Roberson
Walter Roberson 2017년 11월 24일
  댓글 수: 4
NOR AZIEYANI
NOR AZIEYANI 2018년 12월 14일
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 2018년 12월 17일
filename = fullfile(wavdirectory, [matchStr{m} '.wav']);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by