Recent projects that appear in the text-to-speech offline circumstances demand
Been to try to return is also good jacob
Look for the development of record:
1.pom.xml introduced jacob.jar
<dependency> <groupId>com.hynnet</groupId> <artifactId>jacob</artifactId> <version>1.18</version> </dependency>
2. Download jacob, copy jacob-1.18-x64.dll or jacob-1.18-x86.dll to "JAVA_HOME" \ under bin (note versions: JDK version is installed according to choice)
Baidu network disk address: jacob-1.18-M2
Extraction code: ktdn
3.java code is as follows:
Package com.whzc.test; Import com.jacob.activeX.ActiveXComponent; Import com.jacob.com.Dispatch; Import com.jacob.com.Variant; / ** * TTS test * jdk bin files need to import jacob M2-x64.dll--1.17 * @author ZK * @ DATE: 2019 Nian 6 Yue 25 Ri 10:05:21 aM * / public class jacobtest { public static void main (String [] args) {ActiveXComponent AX = null ; STR String = "Please No. 3 to No. A001 window" ; // String str = "Bee Huawei new new"; the try {AX = new newActiveXComponent ( "Sapi.SpVoice" ); // output audio content runs the Dispatch spVoice = ax.getObject (); // Volume 0-100 ax.setProperty ( "Volume", new new the Variant (100 )); // SmartRead speed -10 to +10 ax.setProperty ( "rate", new new the Variant (-2 )); // perform read Dispatch.call (spVoice, "Speak", new new the Variant (STR)); // the following is a build file stream the generated voice file AX = new new ActiveXComponent ( "Sapi.SpFileStream" ); the Dispatch spFileStream =ax.getObject (); AX = new new ActiveXComponent ( "Sapi.SpAudioFormat" ); the Dispatch spAudioFormat = ax.getObject (); // Set the audio stream format Dispatch.put (spAudioFormat, "the Type", new new the Variant (22 is )); // set the file format of the output stream Dispatch.putRef (spFileStream, "the format" , spAudioFormat); // call the output file stream open method, create a .wav file Dispatch.call (spFileStream, "open", new new the Variant ( "E: test.wav \\ "), new new the Variant (. 3), new new the Variant ( to true )); //Sound objects provided as an output audio stream output file object Dispatch.putRef (spVoice, "AudioOutputStream" , spFileStream); // Set the volume to 0 100 Dispatch.put (spVoice, "Volume", new new the Variant (100 )); // setting reading speed Dispatch.put (spVoice, "rate", new new the Variant (-2 )); // start reading Dispatch.call (spVoice, "Speak", new new the Variant (STR)); // close the output file Dispatch.call (spFileStream, "the Close" ); Dispatch.putRef (spVoice, "AudioOutputStream", null ); spAudioFormat.safeRelease(); spFileStream.safeRelease(); spVoice.safeRelease(); ax.safeRelease(); } catch (Exception e) { e.printStackTrace(); } } }
4, run it, the sound system's default voice
Reproduced in: https: //www.cnblogs.com/zktww/p/11083073.html