飞道的博客

【信号处理】男声变女声matlab源码

391人阅读  评论(0)

    把一个人的声音变成别人的声音有二种:一种是:将一个人的声音,变成非特定人的声音,如:把男声变女声,或把小孩子声音变成老人声音。另一种是:将一个人的声音变成特定人的声音,有点像美国电影中那种,A可以通过就变音技术说出B的声音。

     此技术应用领域:一是娱乐性的,如:聊天的最高声音---变音聊天。 二是:有关保密方面,如某长官发布命令,在传播过程中进行变音,让敌方猜不出已方的领导人的身份。三是:被坏人利用。哈哈!

 

     一、变音一般性的描述:

      朋友们平常网上聊天大多是打字聊天! 即累又费时!稍微流行点的就是使用麦克风"摄像头类的东东改变一下聊天的氛围!另类的聊天境界你体验过吗? 那就是可以将自己语音聊天时的声音更换的更有个性!比如:将自己极具磁性的声音,打造成一个极甜美的声音!怎么样!好玩吧?

     一般的音频可以借助电脑声卡的设置再加一软件配合就能实现。

 

     二、变音的主要算法原理

     简单说几种:

     最简单的是:通过对语音的采样率进行变化,就能改变声音,这种是最低的,且不易用参数进行控制。

    别外一种是:提取反应该个性的参数,如,男人、女人;小孩和老人,因声道的长度不一样,导致其基音不一样,进而导致各谐振峰不一样。我们可能通过改变基音和谐振峰的位置来改变声音。


  
  1. function varargout = sound_process(varargin)
  2. % SOUND_PROCESS MATLAB code for sound_process.fig
  3. % SOUND_PROCESS, by itself, creates a new SOUND_PROCESS or raises the existing
  4. % singleton*.
  5. %
  6. % H = SOUND_PROCESS returns the handle to a new SOUND_PROCESS or the handle to
  7. % the existing singleton*.
  8. %
  9. % SOUND_PROCESS('CALLBACK',hObject,eventData,handles,...) calls the local
  10. % function named CALLBACK in SOUND_PROCESS.M with the given input arguments.
  11. %
  12. % SOUND_PROCESS('Property','Value',...) creates a new SOUND_PROCESS or raises the
  13. % existing singleton*. Starting from the left, property value pairs are
  14. % applied to the GUI before sound_process_OpeningFcn gets called. An
  15. % unrecognized property name or invalid value makes property application
  16. % stop. All inputs are passed to sound_process_OpeningFcn via varargin.
  17. %
  18. % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
  19. % instance to run (singleton)".
  20. %
  21. % See also: GUIDE, GUIDATA, GUIHANDLES
  22. % Edit the above text to modify the response to help sound_process
  23. % Last Modified by GUIDE v2.5 03-Sep-2019 22:07:30
  24. % Begin initialization code - DO NOT EDIT
  25. gui_Singleton = 1;
  26. gui_State = struct( 'gui_Name', mfilename, ...
  27. 'gui_Singleton', gui_Singleton, ...
  28. 'gui_OpeningFcn', @sound_process_OpeningFcn, ...
  29. 'gui_OutputFcn', @sound_process_OutputFcn, ...
  30. 'gui_LayoutFcn', [] , ...
  31. 'gui_Callback', []);
  32. if nargin && ischar(varargin{ 1})
  33. gui_State.gui_Callback = str2func(varargin{ 1});
  34. end
  35. if nargout
  36. [varargout{ 1:nargout}] = gui_mainfcn(gui_State, varargin{:});
  37. else
  38. gui_mainfcn(gui_State, varargin{:});
  39. end
  40. % End initialization code - DO NOT EDIT
  41. % --- Executes just before sound_process is made visible.
  42. function sound_process_OpeningFcn(hObject, eventdata, handles, varargin)
  43. % This function has no output args, see OutputFcn.
  44. % hObject handle to figure
  45. % eventdata reserved - to be defined in a future version of MATLAB
  46. % handles structure with handles and user data (see GUIDATA)
  47. % varargin command line arguments to sound_process (see VARARGIN)
  48. % Choose default command line output for sound_process
  49. handles.output = hObject;
  50. handles.h1 = [handles.voice_change,handles.voice_code,handles.exit,handles.func_choose]; %功能选择界面句柄
  51. handles.h2 = [handles.file_choose1,handles.back1,handles.stop1,handles.panel1, ...
  52. handles.play_origin,handles.play_woman,handles.play_fast,handles.play_slow]; %变声器界面
  53. handles.h3 = [handles.file_choose2,handles.back2,handles.figure,handles.play_origin2,...
  54. handles.play_code,handles.draw_origin,handles.draw_code]; %语音加密界面
  55. global a1 b1 c1 a2 b2 c2; %文件打开的状态参量
  56. c1 = 0;
  57. c2 = 0;
  58. global origin_voice1 origin_voice2 man_voice woman_voice ; %
  59. % Update handles structure
  60. guidata(hObject, handles);
  61. % UIWAIT makes sound_process wait for user response (see UIRESUME)
  62. % uiwait(handles.figure1);
  63. % --- Outputs from this function are returned to the command line.
  64. function varargout = sound_process_OutputFcn(hObject, eventdata, handles)
  65. % varargout cell array for returning output args (see VARARGOUT);
  66. % hObject handle to figure
  67. % eventdata reserved - to be defined in a future version of MATLAB
  68. % handles structure with handles and user data (see GUIDATA)
  69. % Get default command line output from handles structure
  70. varargout{ 1} = handles.output;
  71. % --- Executes on button press in voice_change.
  72. function voice_change_Callback(hObject, eventdata, handles)
  73. % hObject handle to voice_change (see GCBO)
  74. % eventdata reserved - to be defined in a future version of MATLAB
  75. % handles structure with handles and user data (see GUIDATA)
  76. set(handles.h1, 'Visible', 'off');
  77. set(handles.h2, 'Visible', 'on');
  78. % --- Executes on button press in voice_code.
  79. function voice_code_Callback(hObject, eventdata, handles)
  80. % hObject handle to voice_code (see GCBO)
  81. % eventdata reserved - to be defined in a future version of MATLAB
  82. % handles structure with handles and user data (see GUIDATA)
  83. set(handles.h1, 'Visible', 'off');
  84. set(handles.h3, 'Visible', 'on');
  85. % --- Executes on button press in exit.
  86. function exit_Callback(hObject, eventdata, handles)
  87. % hObject handle to exit (see GCBO)
  88. % eventdata reserved - to be defined in a future version of MATLAB
  89. % handles structure with handles and user data (see GUIDATA)
  90. %按退出键退出当前程序
  91. clear sound;
  92. try
  93. delete(sound_process);
  94. end
  95. % --- Executes on button press in file_choose1.
  96. function file_choose1_Callback(hObject, eventdata, handles)
  97. % hObject handle to file_choose1 (see GCBO)
  98. % eventdata reserved - to be defined in a future version of MATLAB
  99. % handles structure with handles and user data (see GUIDATA)
  100. clear sound;
  101. global a1 b1 c1 ;
  102. [a1,b1,c1] = uigetfile( '.wav', '选择原始声音文件');
  103. if c1 == 0
  104. warndlg( '请选择音频文件', '警告');
  105. end
  106. % --- Executes during object creation, after setting all properties.
  107. function func_choose_CreateFcn(hObject, eventdata, handles)
  108. % hObject handle to func_choose (see GCBO)
  109. % eventdata reserved - to be defined in a future version of MATLAB
  110. % handles empty - handles not created until after all CreateFcns called
  111. % --- Executes on button press in back1.
  112. function back1_Callback(hObject, eventdata, handles)
  113. % hObject handle to back1 (see GCBO)
  114. % eventdata reserved - to be defined in a future version of MATLAB
  115. % handles structure with handles and user data (see GUIDATA)
  116. clear sound;
  117. set(handles.h1, 'Visible', 'on');
  118. set(handles.h2, 'Visible', 'off');
  119. set(handles.h2, 'Visible', 'off');
  120. c1 = 0;
  121. try
  122. delete(allchild(handles.h2));
  123. end
  124. % --- Executes on button press in file_choose2.
  125. function file_choose2_Callback(hObject, eventdata, handles)
  126. % hObject handle to file_choose2 (see GCBO)
  127. % eventdata reserved - to be defined in a future version of MATLAB
  128. % handles structure with handles and user data (see GUIDATA)
  129. clear sound;
  130. global a2 b2 c2;
  131. [a2,b2,c2] = uigetfile( '.wav', '选择原始声音文件');
  132. if c2 == 0
  133. warndlg( '请选择音频文件', '警告');
  134. end
  135. % --- Executes on button press in back2.
  136. function back2_Callback(hObject, eventdata, handles)
  137. % hObject handle to back2 (see GCBO)
  138. % eventdata reserved - to be defined in a future version of MATLAB
  139. % handles structure with handles and user data (see GUIDATA)
  140. clear sound;
  141. set(handles.h1, 'Visible', 'on');
  142. set(handles.h2, 'Visible', 'off');
  143. set(handles.h3, 'Visible', 'off');
  144. c2 = 0;
  145. try
  146. delete(allchild(handles.figure));
  147. delete(allchild(handles.h3));
  148. end
  149. % --- Executes during object creation, after setting all properties.
  150. function panel1_CreateFcn(hObject, eventdata, handles)
  151. % hObject handle to panel1 (see GCBO)
  152. % eventdata reserved - to be defined in a future version of MATLAB
  153. % handles empty - handles not created until after all CreateFcns called
  154. % --- Executes on button press in play_origin.
  155. function play_origin_Callback(hObject, eventdata, handles)
  156. % hObject handle to play_origin (see GCBO)
  157. % eventdata reserved - to be defined in a future version of MATLAB
  158. % handles structure with handles and user data (see GUIDATA)
  159. clear sound;
  160. global a1 b1 c1 origin_voice1;
  161. if c1 == 0
  162. warndlg( '请先选择音频文件', '警告');
  163. else
  164. origin_voice1=[b1,a1];
  165. fs = 22050;
  166. [audio1,fs] = audioread(origin_voice1);
  167. sound(audio1,fs);
  168. end
  169. % --- Executes on button press in play_woman.
  170. function play_woman_Callback(hObject, eventdata, handles)
  171. % hObject handle to play_woman (see GCBO)
  172. % eventdata reserved - to be defined in a future version of MATLAB
  173. % handles structure with handles and user data (see GUIDATA)
  174. clear sound;
  175. global a1 b1 c1 origin_voice1;
  176. if c1 == 0
  177. warndlg( '请先选择音频文件', '警告');
  178. % --- Executes on button press in draw_code.
  179. function draw_code_Callback(hObject, eventdata, handles)
  180. % hObject handle to draw_code (see GCBO)
  181. % eventdata reserved - to be defined in a future version of MATLAB
  182. % handles structure with handles and user data (see GUIDATA)
  183. global a2 b2 c2 origin_voice2;
  184. if c2 == 0
  185. warndlg( '请先选择音频文件', '警告');
  186. else
  187. origin_voice2=[b2,a2];
  188. fs = 22050;
  189. [audio2,fs] = audioread(origin_voice2);
  190. x1=audio2(:, 1); %取单列
  191. N=length(x1);
  192. n= 0:N- 1;
  193. t=( 0:(N- 1))/fs;
  194. y1 = cos( 50000 * t);
  195. e = x1 .* y1';
  196. f= 0:fs/N:fs*(N- 1)/N;
  197. w= 400000*f/fs;
  198. A3=fft(e,N);
  199. plot(handles.figure,w,abs(A3));
  200. end
  201. % --- Executes during object creation, after setting all properties.
  202. function figure_CreateFcn(hObject, eventdata, handles)
  203. % hObject handle to figure (see GCBO)
  204. % eventdata reserved - to be defined in a future version of MATLAB
  205. % handles empty - handles not created until after all CreateFcns called
  206. % Hint: place code in OpeningFcn to populate figure
  207. % --- Executes on button press in play_slow.
  208. function play_slow_Callback(hObject, eventdata, handles)
  209. % hObject handle to play_slow (see GCBO)
  210. % eventd

完整代码或仿真咨询QQ1575304183


转载:https://blog.csdn.net/m0_57702748/article/details/117266705
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场