필터 지우기
필터 지우기

when I run this code it gives me an error message but I can not figure out what is the problem?

조회 수: 2 (최근 30일)
clc
clear all
% Record your voice for 5 seconds.
radiorec = audiorecorder;
disp('Start speaking.')
recordblocking(radiorec, 5);
disp('End of Recording.');
audiowrite('C:\Users\201802108\Desktop\EN7060_Project\radio.wav', y, fs)
[y, fs] = audioread('radio.wav')
y = y(:, 1);
n = length(y)
t = (0:n-1)/fs
n/fs
% Play back the recording.
sound(y, fs);
% Plot the waveform.
plot(t, y);
The error is:
Undefined function or variable 'y'.
Error in Two_way_radio_system1 (line 9)
audiowrite('C:\Users\201802108\Desktop\EN7060_Project\radio.wav', y, fs)

답변 (1개)

Geoff Hayes
Geoff Hayes 2021년 12월 20일
편집: Geoff Hayes 2021년 12월 20일
@Faisal Alrafaei - you are trying to use the variable y before it has been defined
audiowrite('C:\Users\201802108\Desktop\EN7060_Project\radio.wav', y, fs)
Try getting the audio data and the sampling rate before writing to file
y = getaudiodata(radiorec);
fs = get(radiorec,'SampleRate');
audiowrite('C:\Users\201802108\Desktop\EN7060_Project\radio.wav', y, fs)
Note that you may want to use different variable names for y and fs so as not to conflict with the same variables that you are reading in (later couple lines of code).

카테고리

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