How to play .wav

50 ビュー (過去 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 Center および File ExchangeAudio and Video Data についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by