如何在Android上的音频文件中保存TTS输出?

时间:2012-02-10 15:04:20

标签: android text-to-speech

这是我在这里的第一篇文章。我是Android编程的新手。我想创建一个应用程序,我可以将文本的输出保存到一个音频文件到我的数据库。我听说过 synthesizeToFile(),但事实并非如此。

4 个答案:

答案 0 :(得分:8)

synthesizeToFile()应该创建一个wav(你可以解码并发送到你的数据库或保存为文件或你正在做的任何事情),你可以使用Nitesh的代码来回放它。

来自http://android-developers.blogspot.fi/2009/09/introduction-to-text-to-speech-in.html

HashMap<String, String> myHashRender = new HashMap();
String wakeUpText = "Are you up yet?";
String destFileName = "/sdcard/myAppCache/wakeUp.wav";
myHashRender.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, wakeUpText);
mTts.synthesizeToFile(wakeUpText, myHashRender, destFileName);
  

一旦您收到合成完成的通知,您就可以播放了   输出文件就像任何其他音频资源一样   android.media.MediaPlayer。

答案 1 :(得分:1)

使用此代码并从assets文件夹中获取mp3文件并尝试此代码。

mMediaPlayer = new MediaPlayer();
mMediaPlayer = MediaPlayer.create(this,R.raw.button);
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mMediaPlayer.start();
mMediaPlayer.setOnCompletionListener(new OnCompletionListener() {                   
    @Override
    public void onCompletion(MediaPlayer mp) {
        mMediaPlayer.stop();
    }
});

答案 2 :(得分:0)

您应该保存在tts文件资产文件夹中。

答案 3 :(得分:0)

mTTS =新的TextToSpeech(此为新的TextToSpeech.OnInitListener()

Notice: Trying to get property 'data' of non-object in /home/customer/www/example.com/public_html/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(65) : eval()'d code on line 32

Notice: Trying to get property 'status' of non-object in /home/customer/www/example.com/public_html/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(65) : eval()'d code on line 32
status:

Notice: Trying to get property 'data' of non-object in /home/customer/www/example.com/public_html/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(65) : eval()'d code on line 33

Notice: Trying to get property 'timesActivated' of non-object in /home/customer/www/example.com/public_html/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(65) : eval()'d code on line 33
times activated:

Notice: Trying to get property 'data' of non-object in /home/customer/www/example.com/public_html/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(65) : eval()'d code on line 34

Notice: Trying to get property 'timesActivatedMax' of non-object in /home/customer/www/example.com/public_html/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(65) : eval()'d code on line 34
times activated max:

Notice: Trying to get property 'data' of non-object in /home/customer/www/example.com/public_html/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(65) : eval()'d code on line 35

Notice: Trying to get property 'updatedAt' of non-object in /home/customer/www/example.com/public_html/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(65) : eval()'d code on line 35
last update: