【问题标题】:Best way for convert speech to Pronunciation将语音转换为发音的最佳方法
【发布时间】:2014-04-19 15:08:35
【问题描述】:

我想构建一个识别语音并将其转换为发音文本的 Android 应用程序(即比较特殊单词和用户语音之间的真实发音或重音)。我只知道可以将语音创建为文本。 我想转换用户说的任何单词。

是否有任何 API 可以做到这一点?如果没有,请帮助我如何实现它。

【问题讨论】:

  • 检查ispikit.com
  • 这不是我想要的。 android库不是免费的。我正在寻找更灵活的方式。难度不重要。
  • 如果你想要一个免费的图书馆,你可能想在问题中指出它。

标签: android speech-recognition diacritics speech


【解决方案1】:

我只是给出一个语音到文本的代码。这是一个演示。我不知道这会对你有帮助。但我将它用于我的应用程序。尝试使用它。

SpeechtoText.java

public class SpeechtoText extends Activity {
protected static final int RESULT_SPEECH = 1;
private ImageButton btnSpeak;
private TextView txtText;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    txtText = (TextView) findViewById(R.id.txtText);
    btnSpeak = (ImageButton) findViewById(R.id.btnSpeak);
    btnSpeak.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(
                    RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
            intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");
            try {
                startActivityForResult(intent, RESULT_SPEECH);
                txtText.setText("");
            } catch (ActivityNotFoundException a) {
                Toast t = Toast.makeText(getApplicationContext(),
                        "Ops! Your device doesn't support Speech to Text",
                        Toast.LENGTH_SHORT);
                t.show();
            }
        }
       });
   }
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case RESULT_SPEECH: {
        if (resultCode == RESULT_OK && null != data) {
            ArrayList<String> text = data
                    .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            txtText.setText(text.get(0));
        }
        break;
    }
    }
}

}

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/textView1"
android:layout_toLeftOf="@+id/textView1"
android:gravity="center"
android:orientation="vertical" >
<ImageButton
    android:id="@+id/btnSpeak"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginTop="10dp"
    android:contentDescription="@string/speak"
    android:src="@android:drawable/ic_btn_speak_now" />
  <TextView
    android:id="@+id/txtText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginTop="10dp"
    android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>

【讨论】:

    【解决方案2】:

    这些库可能适合您。我个人没有在 Android 中使用过它们,但它们是 Java 的包。

    看看这个答案: https://stackoverflow.com/a/9055291/3662013

    【讨论】:

      【解决方案3】:

      Android 有一种使用 SpeechRecognizer 类为开发人员提供语音识别的原生方式。

      这个答案很好地解释了使用这个 API 的利弊:

      Offline Speech Recognition In Android (JellyBean)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-01-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多