- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试将 freetts 用于一个简单的 java 应用程序,但我遇到了一个问题,谁能告诉我如何将从文本转换为语音的输出语音保存到程序中的 wave 文件中。我想通过代码来完成。
这是随示例提供的示例 helloworld 应用程序
/**
* Copyright 2003 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and
* redistribution of this file, and for a DISCLAIMER OF ALL
* WARRANTIES.
*/
import com.sun.speech.freetts.FreeTTS;
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
import com.sun.speech.freetts.audio.JavaClipAudioPlayer;
/**
* Simple program to demonstrate the use of the FreeTTS speech
* synthesizer. This simple program shows how to use FreeTTS
* without requiring the Java Speech API (JSAPI).
*/
public class FreeTTSHelloWorld {
/**
* Example of how to list all the known voices.
*/
public static void main(String[] args) {
// listAllVoices();
FreeTTS freetts;
String voiceName = "kevin16";
System.out.println();
System.out.println("Using voice: " + voiceName);
/* The VoiceManager manages all the voices for FreeTTS.
*/
VoiceManager voiceManager = VoiceManager.getInstance();
Voice helloVoice = voiceManager.getVoice(voiceName);
if (helloVoice == null) {
System.err.println(
"Cannot find a voice named "
+ voiceName + ". Please specify a different voice.");
System.exit(1);
}
/* Allocates the resources for the voice.
*/
helloVoice.allocate();
/* Synthesize speech.
*/
helloVoice.speak("Thank you for giving me a voice. "
+ "I'm so glad to say hello to this world.");
/* Clean up and leave.
*/
helloVoice.deallocate();
System.exit(0);
}
}
此代码运行良好我想将输出保存为磁盘上的音频文件。
谢谢呼吸机
最佳答案
我想出了如何做到这一点,你必须简单地使用 SingleFileAudioPlayer
传递你想要的文件名和文件类型,示例声明如下:
audioPlayer = new SingleFileAudioPlayer("output",Type.WAVE);
现在您需要将 SinglefileAudioplayer
对象附加到您的 VoiceManager
对象:例如
helloVoice.setAudioPlayer(audioPlayer);
现在使用:
hellovoice.speak("zyxss");
这将保存文件中的任何内容。请记住关闭音频播放器,否则文件将无法保存。在退出前放置 audioPlayer.close();
。
这是将文件转储到您的 C 目录中的完整工作代码
/**
* Copyright 2003 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and
* redistribution of this file, and for a DISCLAIMER OF ALL
* WARRANTIES.
*/
import com.sun.speech.freetts.FreeTTS;
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
import com.sun.speech.freetts.audio.AudioPlayer;
import com.sun.speech.freetts.audio.SingleFileAudioPlayer;
import javax.sound.sampled.AudioFileFormat.Type;
/**
* Simple program to demonstrate the use of the FreeTTS speech
* synthesizer. This simple program shows how to use FreeTTS
* without requiring the Java Speech API (JSAPI).
*/
public class FreeTTSHelloWorld {
/**
* Example of how to list all the known voices.
*/
public static void main(String[] args) {
// listAllVoices();
FreeTTS freetts;
AudioPlayer audioPlayer = null;
String voiceName = "kevin16";
System.out.println();
System.out.println("Using voice: " + voiceName);
/* The VoiceManager manages all the voices for FreeTTS.
*/
VoiceManager voiceManager = VoiceManager.getInstance();
Voice helloVoice = voiceManager.getVoice(voiceName);
if (helloVoice == null) {
System.err.println(
"Cannot find a voice named "
+ voiceName + ". Please specify a different voice.");
System.exit(1);
}
/* Allocates the resources for the voice.
*/
helloVoice.allocate();
/* Synthesize speech.
*/
//create a audioplayer to dump the output file
audioPlayer = new SingleFileAudioPlayer("C://output",Type.WAVE);
//attach the audioplayer
helloVoice.setAudioPlayer(audioPlayer);
helloVoice.speak("Thank you for giving me a voice. "
+ "I'm so glad to say hello to this world.");
/* Clean up and leave.
*/
helloVoice.deallocate();
//don't forget to close the audioplayer otherwise file will not be saved
audioPlayer.close();
System.exit(0);
}
}
关于java - 如何将输出语音存储到 freetts 中的音频文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4027853/
我正在编写一个使用 Java 语音 API 和 FreeTTS 的应用程序。当我从 Netbeans IDE 运行该应用程序时,该应用程序工作正常,但是当我尝试从本地计算机或其他计算机上的 jar 文
我在我的 java 应用程序中使用了 Freetts.jar 文件来公布 token 号。我的应用程序在我的笔记本电脑上运行良好,但在我的带有外部扬声器的台式机上无法运行。我得到一个空指针异常。注意:
我正在尝试使用 FreeTTS,这是代码: import com.sun.speech.freetts.Voice; import com.sun.speech.freetts.VoiceManage
我写了一个小程序,应该用 Java 简单地进行文本到语音的转换。 我的类(class)是这样的: import com.sun.speech.freetts.Voice; import com.sun
当我尝试使用 FreeTTS 库时,出现错误: Could not validate any MBROLA voices at Some/Location/That/IThought/Held/mbr
我可以使用freetts吗?做一些像语音到文本的转换? 我需要从笔记本电脑的音频输入中检测特定的声音,我可以通过 freetts 来完成吗?在 Java 中? 最佳答案 不,请参阅 freetts F
我正在尝试将 freetts 用于一个简单的 java 应用程序,但我遇到了一个问题,谁能告诉我如何将从文本转换为语音的输出语音保存到程序中的 wave 文件中。我想通过代码来完成。 这是随示例提供的
我正在从事语音识别项目,因此我需要拥有超过数千个单词的音频文件。为了在 FreeTTS 中使用 Mbrola 语音,我已正确完成所有操作,但我只能使用 us1,us2,us3。它没有识别任何其他声音。
这个问题已经有答案了: What is a NullPointerException, and how do I fix it? (12 个回答) 已关闭 5 年前。 我正在尝试制作一个文本转语音程序
我是 FreeTTS 新手,这是我的第一个程序。以下程序只是读出传递的字符串。 如果这很重要的话,我正在使用 Linux Mint 32 位。但是我一天前在我的 Windows 计算机上提取了 jsa
我正在使用 HTML 和 JSP 构建一个 Web 应用程序。提供的功能之一是将一些文本转换为语音。在netbeans中,我创建了一个Java项目,该项目包含一个提供语音任务的Java小程序,该小程序
我正在用 Java 运行一个程序,我在其中使用 FreeTTS Voices,我想要的是改变声音。当我运行它显示的程序时: "System property "mbrola.base" is unde
我正在使用 freeTTS 说出一些文本,在后台我想要一个动画 gif 继续播放当我尝试这样做时:一旦声音开始说话,背景中的图像就会被挂起,即使我将其保留在其他 JFrame 中......并且在语音
首先,如果重要的话,我会使用 Ubuntu linux。 我有一个基于 FreeTTS 和 JSAPI(Java Speech API)的简单项目想法 我已经下载并解压了 FreeTTS 并运行了他们
这是我的代码 import com.sun.speech.freetts.Voice; import com.sun.speech.freetts.VoiceManager; public cla
我正在使用 Java 6 运行 Ubuntu 10.10,但无法让 FreeTTS 输出任何音频。我现在已经在 3 台不同的计算机上尝试过,甚至让我的一个 friend 在他的 Ubuntu PC 上
我正在考虑设置一个文本到语音的解释器,以使我们的 CAPTCHA 挑战符合 ADA 标准。我们是一家 ColdFusion 商店,Ray Camden 已经在去年完成了概念验证。我一直在这里使用他的博
在带有 FreeTTS 的 Java 程序中使用 MBROLA 语音... 我正在用 Java 开发一个简单的文本到语音程序。我决定使用 FreeTTS,但声音并不是我所想的那样,而且我一直在寻找使用
我正在使用 freeTTS用于将文本转换为语音的库。我可以使用这个库编写我的代码,我可以使用以下代码播放特定文本的语音: Voice voice = VoiceManager.getInstance(
当我运行FreeTTS示例时,出现此错误: LINE UNAVAILABLE: Format is pcm_signed 16000.0 Hz 16 bits 1 channel big endian
我是一名优秀的程序员,十分优秀!