如何将Microsoft Text to Speech音频输出到我的计算机中

问题描述 投票:0回答:1

我正在使用Microsoft认知文本进行语音转换的Android应用程序。但是我在播放输出的声音时遇到了问题,因为我不知道如何将音频文件保存到计算机/设备中。

我搜索了许多解决方案,但大多数建议使用Microsoft不支持的synthesizetofile()。

import android.app.AlertDialog;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;
import com.microsoft.speech.tts.Synthesizer;
import com.microsoft.speech.tts.Voice;

public class MainActivity extends AppCompatActivity {
private Synthesizer m_syn;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (getString(R.string.api_key).startsWith("Please")) {
        new AlertDialog.Builder(this)
                .setTitle(getString(R.string.add_subscription_key_tip_title))
                .setMessage(getString(R.string.add_subscription_key_tip))
                .setCancelable(false)
                .show();
    } else {

        if (m_syn == null) {
            // Create Text To Speech Synthesizer.
            m_syn = new Synthesizer(getString(R.string.api_key));
        }

        Toast.makeText(this, "If the wave is not played, please see the log for more information.", Toast.LENGTH_LONG).show();

        m_syn.SetServiceStrategy(Synthesizer.ServiceStrategy.AlwaysService);

        Voice v = new Voice("en-US", "Microsoft Server Speech Text to Speech Voice (en-US, ZiraRUS)", Voice.Gender.Female, true);
        //Voice v = new Voice("zh-CN", "Microsoft Server Speech Text to Speech Voice (zh-CN, HuihuiRUS)", Voice.Gender.Female, true);
        m_syn.SetVoice(v, null);

        // Use a string for speech.
        m_syn.SpeakToAudio(getString(R.string.tts_text));

        // Use SSML for speech.
        String text = "<speak version=\"1.0\" xmlns=\"http://www.w3.org/2001/10/synthesis\" xmlns:mstts=\"http://www.w3.org/2001/mstts\" xml:lang=\"en-US\"><voice xml:lang=\"en-US\" name=\"Microsoft Server Speech Text to Speech Voice (en-US, ZiraRUS)\">You can also use SSML markup for text to speech.</voice></speak>";
        m_syn.SpeakSSMLToAudio(text);

        findViewById(R.id.stop_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                m_syn.stopSound();
            }
        });

        findViewById(R.id.play_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                m_syn.SpeakToAudio(getString(R.string.tts_text));
            }
        });
}}}

非常感谢任何建议或意见

java android text-to-speech microsoft-cognitive microsoft-speech-api
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.