1.前言:

        本代码是笔者参加2024年集创赛紫光同创赛道,在网上的代码,论文,课设等基础上编辑出来的一款带有GUI界面的数字变声器,变声效果良好,可以直接运行,有相关变换说明。

        能够直接打开指定格式的音频文件,实现音频的播放暂停,具有男女声转换,童声转换的功能,且能显示音频的时域图,FFT频谱图,共振峰及基音周期转换前后零极点图,方便对比观察。

2.开发日期:

        2024.2~2024.3

3.开发环境:

        windows11,matlabR2023a

4.音频前置处理:

        建议用AU软件,去除音频前没有声音的部分(matlab在LPC运算时对于向量为0的数据的系数解都为0,在matlab这个软件上得出的结果是(0,naf,naf,……),会对后续运算造成影响),将测试音频格式导出为为“48000Hz单声道32位wav”格式。

5.软件效果:

        男声变女声,女声变男声,男女生变童声,GUI界面可以直接打开选定音频,播放原声,变声的时域图,频谱图进行对比,以及共振峰,基因周期变换前后的零极点图。

变声效果演示视频

 6.变声思路:

1.预处理:

        语音信号读取,端点检测,分帧,预加重,加窗,归一等

2.两个语音信号特征及其关系:

        1.共振峰。2.基音周期。

        共振峰频率的改变是基于重采样实现的,从重采样原理知道,这也同时印发了基频的变化,为保证基频变化和共振峰频率变化的独立、互不相关,在基频移动时必须考虑抵消重采样带来的偏移,理论上只要基频检测足够精确,确实可以保证基频改变和共振峰频率改变间的互不相关。保证变声效果的自然度主要是没有采用基因检测将基因移动和共振峰变化彻底隔离的缘故。

3.线性语音预测:

4.共振峰:

        1.含义:当声门周期脉冲激励信号通过声道时,会在声道内引起共振作用(这个过程在语音产生模型中叫做声道模型),从而产生一组共振频率,这组共振频率就被称为共振峰(频率),通常认为,语音谱包络中的几个极大值就是共振峰频率。准确的检测共振峰频率和带宽,有利于区分不同韵母,从于提高对语音语义的识别度。

        2.求解:①基于线性预测:②选峰法:③倒谱法:

        采用LPC倒谱法提取共振峰:

5.基音周期:

         1.含义:所谓基音周期,就是对这种准周期而言的,它反映了声门相邻两次开闭之间的时间间隔或开闭的频率。 基音周期是语音信号最重要的参数之一,它描述了语音激励源的一个重要特征。基音周期信息在语音识别、说话人识别、语音分析与语音合成,以及低码率语音编码、发音系统疾病诊断、听觉残障者的语言指导等多个领域有着广泛的应用。因为汉语是一种有调语言,基音的变化模式称为声调,它携带着非常重要的具有辨义作用的信息,有区别意义的功能。所以,基音的提取和估算对汉语分析更是一个十分重要的课题。

         2.估计:基因检测大概有三种方法:

①波形估计法:直接由语音波形来估计基音周期,常见的有:自相关法、并行处理法、平均幅度差法、数据减少法等;

②相关处理法:这种方法在语音信号处理中广泛应用,因为其抗波形相位失真能力强,且在硬件处理上结构简单,包括波形自相关法,平均振幅差分函数法(AMDF),简化逆滤波法(SIFT)等;

③变换法:它是一种将语音信号变换到频域或者时域来估计基音周期的方法,首先利用同态分析方法将声道的影响消除,得到属于激励部分的信息,然后求取基音周期,最常用的就是倒谱法,这种方法的缺点就是算法比较复杂,但是基音估计的效果却很好;

        采用短时自相关的基音周期检测:

6.男,女,童声区别:

        

7.部分代码:

function varargout = untitled1(varargin)

% UNTITLED1 MATLAB code for untitled1.fig

% UNTITLED1, by itself, creates a new UNTITLED1 or raises the existing

% singleton*.

%

% H = UNTITLED1 returns the handle to a new UNTITLED1 or the handle to

% the existing singleton*.

%

% UNTITLED1('CALLBACK',hObject,eventData,handles,...) calls the local

% function named CALLBACK in UNTITLED1.M with the given input arguments.

%

% UNTITLED1('Property','Value',...) creates a new UNTITLED1 or raises the

% existing singleton*. Starting from the left, property value pairs are

% applied to the GUI before untitled1_OpeningFcn gets called. An

% unrecognized property name or invalid value makes property application

% stop. All inputs are passed to untitled1_OpeningFcn via varargin.

%

% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one

% instance to run (singleton)".

%

% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help untitled1

% Last Modified by GUIDE v2.5 09-Mar-2024 16:36:56

% Begin initialization code - DO NOT EDIT

gui_Singleton = 1;

gui_State = struct('gui_Name', mfilename, ...

'gui_Singleton', gui_Singleton, ...

'gui_OpeningFcn', @untitled1_OpeningFcn, ...

'gui_OutputFcn', @untitled1_OutputFcn, ...

'gui_LayoutFcn', [] , ...

'gui_Callback', []);

if nargin && ischar(varargin{1})

gui_State.gui_Callback = str2func(varargin{1});

end

if nargout

[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});

else

gui_mainfcn(gui_State, varargin{:});

end

% End initialization code - DO NOT EDIT

% --- Executes just before untitled1 is made visible.

function untitled1_OpeningFcn(hObject, eventdata, handles, varargin)

% This function has no output args, see OutputFcn.

% hObject handle to figure

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% varargin command line arguments to untitled1 (see VARARGIN)

% Choose default command line output for untitled1

handles.output = hObject;

% Update handles structure

guidata(hObject, handles);

% UIWAIT makes untitled1 wait for user response (see UIRESUME)

% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.

function varargout = untitled1_OutputFcn(hObject, eventdata, handles)

% varargout cell array for returning output args (see VARARGOUT);

% hObject handle to figure

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure

varargout{1} = handles.output;

% --- Executes on button press in openfiles.

function yuansheng_Callback(hObject, eventdata, handles)

sound(handles.y1,handles.Fs);

plot(handles.axes1,handles.y1,'Color',[1 0.5 0])

title(handles.axes1,'时域图');

xlabel(handles.axes1,'时间');

ylabel(handles.axes1,'幅度');

y1=fft(handles.y,length(handles.y1));

plot(handles.axes2,abs(y1),'Color',[1 0.5 0]);

xlabel(handles.axes2,'频率');

ylabel(handles.axes2,'幅度');

title(handles.axes2,'FFT频谱图');

% --- Executes on button press in nanbiannv.

function nanbiannv_Callback(hObject, eventdata, handles)

%************************************************男变女********************************************************

% 定义常数

FL = 80; % 帧长

WL = 240; % 窗长

P = 10; % 预测系数个数

s = handles.y;

fs = handles.Fs;

% 定义常数

s = s/max(s); % 归一化

L = length(s); % 读入语音长度

FN = floor(L/FL)-2; % 计算帧数

% 预测和重建滤波器

exc = zeros(L,1); % 激励信号(预测误差)

zi_pre = zeros(P,1); % 预测滤波器的状态

s_rec = zeros(L,1); % 重建语音

zi_rec = zeros(P,1);

% 变调不变速滤波器

exc_syn_t = zeros(L,1); % 合成的激励信号(脉冲串)

s_syn_t = zeros(L,1); % 合成语音

last_syn_t = 0; % 存储上一个(或多个)段的最后一个脉冲的下标

zi_syn_t = zeros(P,1); % 合成滤波器的状态

hw = hamming(WL); % 汉明窗

最后:整个源代码并未给出,可以私,我也可以给你适当的技术支持,教你怎么写。

精彩内容

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: