Effacer les filtres
Effacer les filtres

Why the wav or audio is repeating eventhough I record a new voice. please help me I cant hear my new audio it plays the same audio over again.

3 vues (au cours des 30 derniers jours)
clc
clear all
close all
warning off
Fs=8000;%Sampling frequency in hertz
ch=1;%Number of channels--2 options--1 (mono) or 2 (stereo)
datatype='uint8';
nbits=16;%8,16,or 24
Nseconds=5;
NumS = 5;
%% Create a recorder object
recorder=audiorecorder(Fs,nbits,ch);
datatype='uint8';
%% Record user's voice for 5 sec
disp('Get Ready')
pause(3)
% to record audio data from an input device ...
...such as a microphone for processing in MATLAB
recorder=audiorecorder(Fs,nbits,ch);
disp('Start speaking...')
%Record audio to audiorecorder object,...
...hold control until recording completes
recordblocking(recorder,Nseconds);
disp('End of Recording.');
disp('Recorded');
%Store recorded audio signal in numeric array
x=getaudiodata(recorder,datatype);
%%Training Function
f = voiceFeatures(x);
%%Save Users data
user = cellstr(input('Enter the users name:', 's'));
try
load database
F=[F;f];
C=[C;user];
if numel(F) > 5
F = F(end-4:end);
C = C(end-4:end);
end
save database
catch
F=f;
C=user;
save database F C
end
%Write audio file
[filename, pathname] = uiputfile('*.wav', 'File name for output');
if isnumeric(filename); return; end %user cancel
fullname = fullfile(pathname, filename);
audiowrite(fullname, x, Fs)
%%Training Function
f = voiceFeatures(x);
%%Play users voice
play(recorder);
x= getaudiodata(recorder);
%Store recorded audio signal in numeric array
data=getaudiodata(recorder,datatype);
plot(x)
figure;
disp('done.')
msgbox('Your voice is registered')
  12 commentaires
kim
kim le 21 Déc 2022
like this eventhough I didnt write hello in my user when I register it
Jan
Jan le 22 Déc 2022
Modifié(e) : Jan le 22 Déc 2022
@kim: I've showed you above, how your code can be simplified. Why do you ignore such suggestions?
You display C(index) as output, although C is not created in the code anywhere. Therefore it must be part of the loaded MAT file.
Do not load the contents of a MAT file directly to the workspace, because this provokes such problems frequently. Store the output in a variable instead:
db = load('database.mat');
[smallest_distance, index] = min(abs(db.F - f_test));
Clean up the contents of the database.mat file. It looks like it contains a lot of junk like "NumS" and "Nseconds". Having a bunch of redundant variables increases the confusion level. Files like "colee..wav" and "COLEE.WAV" are a trap also. You do see, that you loose the overview already in a script with 50 lines. So avoid every addition source of troubles: Keep your workspace clean.

Connectez-vous pour commenter.

Réponses (0)

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by