How do I create and save an audio file from the output of text to speech synthesizer

30 ビュー (過去 30 日間)
How do I save an audio file generated by the text to speech synthesizer, for instance using the code given below. My aim is to take the synthesizer audio output and continue processing it. % Program to do text to speech. % Get user's sentence userPrompt = 'What do you want the computer to say?'; titleBar = 'Text to Speech'; defaultString = 'Hello World! MATLAB is an awesome program!'; caUserInput = inputdlg(userPrompt, titleBar, 1, {defaultString}); if isempty(caUserInput) return; end; % Bail out if they clicked Cancel. caUserInput = char(caUserInput); % Convert from cell to string. %*https://www.mathworks.com/matlabcentral/answers/159113-text-to-speech-synthesis-matlab-code#answer_155653*% NET.addAssembly('System.Speech'); obj = System.Speech.Synthesis.SpeechSynthesizer; obj.Volume = 100; Speak(obj, caUserInput);

採用された回答

Jan
Jan 2021 年 6 月 21 日
編集済み: Jan 2021 年 6 月 23 日
And:
NET.addAssembly('System.Speech');
synth = System.Speech.Synthesis.SpeechSynthesizer;
synth.Volume = 100;
synth.SetOutputToWaveFile(fullfile(tempdir, 'yourFile.wav')); % [EDITED, typo]
Speak(synth, 'Hello world');
synth.SetOutputToNull; % [EDITED] Close the file
  11 件のコメント
Walter Roberson
Walter Roberson 2022 年 3 月 4 日
NO.
.wav files are not just a header and then a plain list of samples .
.wav files have a header, and then they have chunks of encoded audio data. Each encoded chunk contains a 4-character code that indicates which encoding technique has been used for the audio data. One might have code 'H243' and another might code 'IND5' for example. A few of the codes are standardized by Microsoft, but vendors are permitted to create their own codes. The 4-character codes are references to algorithms for encoding audio data. Some of the algorithms are public; some of them are known only to one vendor. The simplest algorithm supported just lists the samples out in full. Another algorithm uses the samples unchanged but uses ZIP compression. Other algorithms might use "perceptual encoding". Some algorithms might be secret and might involve encrypted audio data (for example to enforce Digital Rights Management.)
So in order to read audio data from a .wav file, you need the file itself, and you need a program that generally knows the structure of wav files --- and you need a "plug-in" that knows how to decode audio data that has been encoded according to the particular 4-character algorithm.
It would certainly be possible to write a MATLAB program that found the chunk of encoded audio data, and made the encoded data available to the MATLAB user -- but unless you know the algorithm used by the company that did the encoding, you cannot take that and go further to access the audio content.
Imagine for example a similar text system (instead of audio) in which one chunk of data had 4-character code 'SIML' and content "The lock combination is 311724". And then imagine another chunk of data had 4-character code 'SHRT' and content 'Lck cmb CAAGBD' -- same information, algorithm not difficult to figure out. And then imagine another chunk of data had 4-character code 'Mxyz' and content '8yJQ*c' : MATLAB might be able to tell you 'Mxyz' and '8yJQ*c' but it would have no idea how to convert that to meaningful text.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by