一、获取代码方式


二、部分源代码

function  txt2speech(txt,voice,pace,fs)
if ~ispc, error('要求使用Microsoft Win32 SAPI .');
end
if ~ischar(txt), error('第一个参数是字符串.');
end
SV = actxserver('SAPI.SpVoice');
TK = invoke(SV,'GetVoices');
if nargin > 1
for k = 0:TK.Count-1
if strcmpi(voice,TK.Item(k).GetDescription)
SV.Voice = TK.Item(k);
break;
elseif strcmpi(voice,'list')
disp(TK.Item(k).GetDescription);
end
end
end
if nargin > 2
if isempty(pace), pace = 0;
end
if abs(pace) > 10, pace = sign(pace)*10;
end
SV.Rate = pace;
end
if nargin < 4 || ~ismember(fs,[8000,11025,12000,...
16000,22050,24000,32000,44100,48000]), fs = 16000;
end
function txt2speech(txt,voice,pace,fs)
if ~ispc, error('要求使用Microsoft Win32 SAPI .');
end
if ~ischar(txt), error('第一个参数是字符串.');
end
SV = actxserver('SAPI.SpVoice');
TK = invoke(SV,'GetVoices');
if nargin > 1
for k = 0:TK.Count-1
if strcmpi(voice,TK.Item(k).GetDescription)
SV.Voice = TK.Item(k);
break;
elseif strcmpi(voice,'list')
disp(TK.Item(k).GetDescription);
end
end
end
if nargin > 2
if isempty(pace), pace = 0;
end
if abs(pace) > 10, pace = sign(pace)*10;
end
SV.Rate = pace;
end
if nargin < 4 || ~ismember(fs,[8000,11025,12000,...
16000,22050,24000,32000,44100,48000]), fs = 16000;
end
function txt2speech(txt,voice,pace,fs)
if ~ispc, error('要求使用Microsoft Win32 SAPI .');
end
if ~ischar(txt), error('第一个参数是字符串.');
end
SV = actxserver('SAPI.SpVoice');
TK = invoke(SV,'GetVoices');
if nargin > 1
for k = 0:TK.Count-1
if strcmpi(voice,TK.Item(k).GetDescription)
SV.Voice = TK.Item(k);
break;
elseif strcmpi(voice,'list')
disp(TK.Item(k).GetDescription);
end
end
end
if nargin > 2
if isempty(pace), pace = 0;
end
if abs(pace) > 10, pace = sign(pace)*10;
end
SV.Rate = pace;
end
if nargin < 4 || ~ismember(fs,[8000,11025,12000,...
16000,22050,24000,32000,44100,48000]), fs = 16000;
end

三、运行结果

实际效果为语音播报

四、matlab版本及参考文献

1 matlab版本

2014a

2 参考文献

[1]韩纪庆,张磊,郑铁然.语音信号处理(第3版)[M].清华大学出版社,2019.

[2]柳若边.深度学习:语音识别技术实践[M].清华大学出版社,2019.