【问题标题】:how text to speech works in android文本到语音如何在 android 中工作
【发布时间】:2014-03-31 23:14:10
【问题描述】:

我正在使用文本到语音功能创建一个 android 应用程序我使用了内置的文本到语音 我只想知道它是如何在android SDK中开发和维护的,如果有人知道一篇关于在an​​droid中开发文本到语音的论文,我会很幸运

【问题讨论】:

    标签: android text-to-speech android-speech-api


    【解决方案1】:

    这个thread 会有所帮助。此外,在 API 级别 14 中引入了 TTS 引擎实现的抽象类。检查此link。你也可以阅读这篇关于语音合成的information 来指导你应该如何实现它。

    【讨论】:

      【解决方案2】:

      幸运的是,我也在这方面工作,拿走我的代码

      package com.example.texttospeech;
      
      import java.util.Locale;
      
      import android.os.Bundle;
      import android.app.Activity;
      import android.speech.tts.TextToSpeech;
      import android.speech.tts.TextToSpeech.OnInitListener;
      import android.util.Log;
      import android.view.View;
      import android.view.View.OnClickListener;
      import android.widget.Button;
      import android.widget.EditText;
      
      public class MainActivity extends Activity implements OnClickListener, OnInitListener {
      
          private TextToSpeech tts;
          EditText editxt;
              Button b1;
      
      
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
      
      
      
              tts = new  TextToSpeech(this , this);
              editxt = (EditText) findViewById(R.id.editText1);
              b1 = (Button) findViewById(R.id.read);
              b1.setOnClickListener(this);
          }
          @Override
          public void onClick(View v) {
              switch (v.getId()) {
              case R.id.read:
                  convert_text();
                  break;
      
              default:
                  break;
              }
      
          }
          private void convert_text() {
              String speech = editxt.getText().toString();
              tts.speak(speech, TextToSpeech.QUEUE_FLUSH, null);
      
          }
          @Override
          public void onInit(int status) {
              if(status == TextToSpeech.SUCCESS){
                  int result = tts.setLanguage(Locale.getDefault());
                  if(result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED){  
                      Log.e("DEBUG" , "Language Not Supported");}
                  else{
                      b1.setEnabled(true);
                      convert_text();
                  }
      
              }
              else{
                  Log.i("DEBUG" , "MISSION FAILED");
              }
      
          }
      
          @Override
          protected void onDestroy() {
              super.onDestroy();
              if (tts != null){
                  tts.stop();
                  tts.shutdown();
              }
          }
      
      }
      

      mylayout activity_main.xml

      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:paddingBottom="@dimen/activity_vertical_margin"
          android:paddingLeft="@dimen/activity_horizontal_margin"
          android:paddingRight="@dimen/activity_horizontal_margin"
          android:paddingTop="@dimen/activity_vertical_margin"
          tools:context=".MainActivity" >
      
          <TextView
              android:id="@+id/textView1"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignParentTop="true"
              android:layout_centerHorizontal="true"
              android:textSize="21sp"
              android:layout_marginTop="23dp"
              android:text="Text To Speech Test" />
      
          <EditText
              android:id="@+id/editText1"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_below="@+id/textView1"
              android:layout_centerHorizontal="true"
              android:layout_marginTop="35dp"
              android:ems="10" />
      
          <Button
              android:id="@+id/read"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignLeft="@+id/textView1"
              android:layout_below="@+id/editText1"
              android:layout_marginLeft="46dp"
              android:layout_marginTop="50dp"
              android:text="Read" />
      
      </RelativeLayout>
      

      【讨论】:

      • 这是使用内置的。他/她想知道它是如何构建/实现的
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多