A list,

Voice broadcast based on MATLAB

Ii. Source code

function  txt2speech(txt,voice,pace,fs)
if ~ispc, error('Microsoft Win32 SAPI required.');
end
if ~ischar(txt), error('The first argument is a string.');
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 required.');
end
if ~ischar(txt), error('The first argument is a string.');
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 required.');
end
if ~ischar(txt), error('The first argument is a string.');
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
Copy the code

3. Operation results

The actual effect is voice broadcast

Fourth, note

Version: 2014 a