如何节省TTS输出在Android上的音频文件?音频文件、节省、TTS、Android

2023-09-06 17:08:21 作者:钢铁汉子@

这是我的第一篇文章在这里。我是新的Andr​​oid的编程。我想创建一个应用程序,我可以将文本到语音的输出保存到一个音频文件到我的数据库。我听说过的 synthesizeToFile()的,但它不是。

this is my first post here. I'm new in Android Programming. I want to create an app where I can save the output of the text to speech into an audio file to my database. I've heard about synthesizeToFile() but It's not it.

推荐答案

使用这种code,并从资产文件夹中的MP3文件的接取和尝试这个code。

Use this code and get the mp3 file acess from the assets folder and try this code.

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();
    }
});