900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > java利用jacob 文字转语音文件 windows

java利用jacob 文字转语音文件 windows

时间:2022-06-03 12:33:03

相关推荐

java利用jacob 文字转语音文件 windows

public static void testToSpeech(String text) {ActiveXComponent activeXComponent = new ActiveXComponent("Sapi.SpVoice");//运行时输出语音内容Dispatch dispatch = activeXComponent.getObject();//文件名称try{//生成语音文件activeXComponent = new ActiveXComponent("Sapi.SpFileStream");Dispatch fileStreamDispatch = activeXComponent.getObject();//音频activeXComponent = new ActiveXComponent("Sapi.SpAudioFormat");Dispatch audioDispatch = activeXComponent.getObject();//设置文件流格式Dispatch.putRef(fileStreamDispatch, "Format", audioDispatch);//设置音频流格式Dispatch.put(audioDispatch, "Type", new Variant(22));//调用输出文件流打开方法,创建一个.wav .mp3 .mp4 .wma文件Dispatch.call(fileStreamDispatch, "Open", new Variant("C:\\call.wav"),new Variant(3),new Variant(true));//设置声音对象的音频流输出流为输出文件对象Dispatch.putRef(dispatch, "AudioOutputStream", fileStreamDispatch);//设置音量0-100Dispatch.put(dispatch, "Volume", new Variant(100));//设置朗读速度Dispatch.put(dispatch, "Rate", new Variant(-2));//开始朗读Dispatch.call(dispatch, "Speak",new Variant(text));//关闭输出文件流Dispatch.call(fileStreamDispatch, "Close");Dispatch.putRef(dispatch, "AudioOutputStream", null);audioDispatch.safeRelease();fileStreamDispatch.safeRelease();dispatch.safeRelease();activeXComponent.safeRelease();}catch (Exception e) {e.printStackTrace();}}

<dependency><groupId>com.hynnet</groupId><artifactId>jacob</artifactId><version>1.18</version></dependency>

自行找到jacob-1.18-x64.dll,放入jdk安装目录下的bin文件夹

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。