function wav = tts(txt,voice,pace,fs)%TTS text to speech.% TTS (TXT) synthesizes speech from string TXT, and speaks it. The audio% format is mono, 16 bit, 16k Hz by default.% % WAV = TTS(TXT) does not vocalize but output to the variable WAV.%% TTS(TXT,VOICE) uses the specific voice. Use TTS('','List') to see a% list of availble voices. Default is the first voice.%% TTS(...,PACE) set the pace of speech to PACE. PACE ranges from % -10 (slowest) to 10 (fastest). Default 0.%% TTS(...,FS) set the sampling rate of the speech to FS kHz. FS must be% one of the following: 8000, 11025, 12000, 16000, 22050, 24000, 32000,% 44100, 48000. Default 16.% % This function requires the Microsoft Win32 Speech API (SAPI).%% Examples:% % Speak the text;% tts('I can speak.');% % List availble voices;% tts('I can speak.','List');% % Do not speak out, store the speech in a variable;% w = tts('I can speak.',[],-4,44100);% wavplay(w,44100);%% See also WAVREAD, WAVWRITE, WAVPLAY.% Written by Siyi Deng; 12-21-2007;if ~ispc, error('Microsoft Win32 SAPI is required.'); endif ~ischar(txt), error('First input must be string.'); endSV = actxserver('SAPI.SpVoice');%創建一個object對象COM.SAPI_SpVoiceTK = invoke(SV,'GetVoices');%創建一個object對象Interface.928....if nargin > 1 %判斷參數多余一個 % Select voice;%根據文字選擇中文發音對象或者英文發音對象?;蜻@系統中的其他國家語言發音對象 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 % Set pace; if nargin > 2 if isempty(pace), pace = 0; end %如果pace為空那么默認不加速 if abs(pace) > 10, pace = sign(pace)*10; end %如果加/減速大于10那么只取左右端的極限 SV.Rate = pace;%接口語音速率設置 endendif nargin < 4 || ~ismember(fs,[8000,11025,12000,16000,22050,24000,32000,... 44100,48000]), fs = 16000; end %如果沒有采樣頻率或者采樣頻率取值不再規定成員里面,那么使用默認值 16kHzif nargout > 0 %如果函數有輸入參數 % Output variable; MS = actxserver('SAPI.SpMemoryStream');%創建COM.API_SpMemoryStream對象 MS.Format.Type = s
新聞熱點
疑難解答