How can I record the sound produced after the LPC Algorithm?

1 回表示 (過去 30 日間)
Mert Sari
Mert Sari 2024 年 1 月 22 日
回答済み: Sulaymon Eshkabilov 2024 年 1 月 22 日
Hello, I will prepare slides for my homework and I want to record the sound I get from matlab after the LPC algorithm. And this way I will be able to use it on my slide. I wonder if this is possible? And how can I?
Also, my lpc code is;
%MAIN BODY
clear all;
clc;
%TAKING INPUT WAVEFILE,
inpfilenm = '3853-163249-0002.wav';
[y, Fs] =audioread(inpfilenm);
% x=wavrecord(,);
%LENGTH (IN SEC) OF INPUT WAVEFILE,
t=length(y)./Fs;
sprintf('Processing the wavefile "%s"', inpfilenm)
sprintf('The wavefile is %3.2f seconds long', t)
%THE ALGORITHM STARTS HERE,
M=10; %prediction order
[aCoeff, pitch_plot, voiced, gain] = f_ENCODER(y, Fs, M); %pitch_plot is pitch periods
synth_speech = f_DECODER (aCoeff, pitch_plot, voiced, gain);
%RESULTS,
beep;
disp('Press a key to play the original sound!');
pause;
soundsc(y, Fs);
disp('Press a key to play the LPC compressed sound!');
pause;
soundsc(synth_speech, Fs);
s0=snr(y);
disp(" Original audio SNR in dB " + s0)
s1=snr(synth_speech);
disp(" LPC audio SNR in dB " + s1)
% CALCULATING COMPRESSION RATIO
original_size = numel(y) * 2 * 32; % 64 bits per sample
encoded_size = numel(aCoeff) * 2.4; % LPC 2.4k
compression_ratio = original_size / encoded_size;
disp(['Compression Ratio for LPC: ', num2str(compression_ratio)]);
figure;
subplot(2,1,1),
plot(y),
xlabel("Per Samples"),
ylabel("Amplitude"),
title(['Original signal = "', inpfilenm, '"']),
grid on %title('original signal = "%s"', inpfilenm);
subplot(2,1,2),
plot(synth_speech),
xlabel("Per Samples"),
ylabel("Amplitude"),
title(['synthesized speech of "', inpfilenm, '" using LPC algo']),grid on
Also, my homework is speech processing with LPC, CELP and DCT algorithms.

回答 (1 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2024 年 1 月 22 日
If understood correctly, you are trying to record the filtered sounds. If so, audiowrite() can solve the task (to export the filtered data in .wav file that can be embedded in a PPT slide), e.g.:
%MAIN BODY
clearvars
clc
%TAKING INPUT WAVEFILE,
inpfilenm = '3853-163249-0002.wav';
[y, Fs] =audioread(inpfilenm);
% x=wavrecord(,);
%LENGTH (IN SEC) OF INPUT WAVEFILE,
t=length(y)./Fs;
sprintf('Processing the wavefile "%s"', inpfilenm)
sprintf('The wavefile is %3.2f seconds long', t)
%THE ALGORITHM STARTS HERE,
M=10; %prediction order
[aCoeff, pitch_plot, voiced, gain] = f_ENCODER(y, Fs, M); %pitch_plot is pitch periods
synth_speech = f_DECODER (aCoeff, pitch_plot, voiced, gain);
%RESULTS,
beep;
disp('Press a key to play the original sound!');
pause;
soundsc(y, Fs);
disp('Press a key to play the LPC compressed sound!');
pause;
soundsc(synth_speech, Fs);
s0=snr(y);
disp(" Original audio SNR in dB " + s0)
s1=snr(synth_speech);
disp(" LPC audio SNR in dB " + s1)
% CALCULATING COMPRESSION RATIO
original_size = numel(y) * 2 * 32; % 64 bits per sample
encoded_size = numel(aCoeff) * 2.4; % LPC 2.4k
compression_ratio = original_size / encoded_size;
disp(['Compression Ratio for LPC: ', num2str(compression_ratio)]);
figure;
subplot(2,1,1),
plot(y),
xlabel("Per Samples"),
ylabel("Amplitude"),
title(['Original signal = "', inpfilenm, '"']),
grid on %title('original signal = "%s"', inpfilenm);
subplot(2,1,2),
plot(synth_speech),
xlabel("Per Samples"),
ylabel("Amplitude"),
title(['synthesized speech of "', inpfilenm, '" using LPC algo']),grid on
% Save the filtered sound signal as a *.WAV file:
File_Name = 'Output_Sound.wav';
audiowrite(File_Name, synth_speech, Fs);

カテゴリ

Help Center および File ExchangeSimulation, Tuning, and Visualization についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by