【问题标题】:TTS not working in tensorflow for gesture detection android appTTS 在 tensorflow 中无法用于手势检测 Android 应用
【发布时间】:2021-07-04 11:39:52
【问题描述】:
  • 我正在制作一个手势检测应用程序,如果您在其中执行 ASL,它会检测您正在执行的标志并显示如下所示的结果。

  • 我还实现了一个EditText 字段,在该字段中检索结果。我正在尝试Text-To-SpeechTTS

  • 我正在使用Log.i("Recognitionss", String.valueOf(results.get(0).getTitle())); 将结果记录到DetectorActivity.java

  • 生成的日志结果如下所示,我已将其传递给XML 文件

2021-04-14 19:34:24.826 29814-29924/org.tensorflow.lite.examples.detection I/Recognitionss: L
2021-04-14 19:34:24.835 29814-29924/org.tensorflow.lite.examples.detection I/tensorflow: MultiBoxTracker: Processing 1 results from 123
2021-04-14 19:34:24.855 29814-29814/org.tensorflow.lite.examples.detection I/tensorflow: DetectorActivity: Preparing image 128 for detection in bg thread.
2021-04-14 19:34:24.876 29814-29924/org.tensorflow.lite.examples.detection I/tensorflow: DetectorActivity: Running detection on image 128
  • 我已将ButtonEditText 添加到我的bottom sheet 导航中。
        <Button
            android:id="@+id/btnSpeak"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/textView1"
            android:layout_below="@+id/textView1"
            android:layout_marginTop="10dp"
            android:text="Voice Conversion" />

        <EditText
            android:id="@+id/txtText"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:inputType="text"/>
  • TTS 的 Java 代码
package org.tensorflow.lite.examples.detection;

import android.os.Build;
import android.speech.tts.TextToSpeech;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

import java.util.Locale;

public class AndroidTextToSpeechActivity extends AppCompatActivity {

    Button btnSpeak;
    EditText editText;

    TextToSpeech textToSpeech;

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

        // Init TextToSpeech
        textToSpeech = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(int status) {
                if (status == TextToSpeech.SUCCESS) {
                    int result = textToSpeech.setLanguage(Locale.ENGLISH);
                    if (result == TextToSpeech.LANG_MISSING_DATA ||
                            result == TextToSpeech.LANG_NOT_SUPPORTED) {
                        Toast.makeText(getApplicationContext(), "This language is not supported!",
                                Toast.LENGTH_SHORT);
                    } else {
                        btnSpeak.setEnabled(true);
                        textToSpeech.setPitch(0.6f);
                        textToSpeech.setSpeechRate(1.0f);

                        speak();
                    }
                }
            }
        });

        // Init View
        btnSpeak = (Button)findViewById(R.id.btnSpeak);
        editText = (EditText)findViewById(R.id.txtText);

        btnSpeak.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                speak();
            }
        });
    }

    private void speak() {
        String text = editText.getText().toString();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            textToSpeech.speak(text, TextToSpeech.QUEUE_FLUSH, null, null);
        } else {
            textToSpeech.speak(text, TextToSpeech.QUEUE_FLUSH, null);
        }
    }

    @Override
    protected void onDestroy() {
        if (textToSpeech != null) {
            textToSpeech.stop();
            textToSpeech.shutdown();
        }
        super.onDestroy();
    }
}

  • 问题是当我点击按钮时没有语音反馈,控制台或logcat中也没有错误。

【问题讨论】:

  • 你能记录这个 _public void onInit(int status) { _ status value 来检查你得到什么状态
  • @kelvin 我已经用我的解决方案更新了我的问题,所以我将不再实施任何东西,因为我已经得到了我想要的输出。
  • 所以只需将其作为答案发布并接受您自己的答案,以免引起注意。
  • 好的,谢谢。对造成的不便深表歉意。

标签: java android tensorflow text-to-speech gesture-recognition


【解决方案1】:
  • 解决方案
  • 在其中添加了以下代码,其中添加了textviewimageview,您可以使用按钮或任何您喜欢使用的东西,这给了我以下输出。
  • 然后在CameraActivity.java 下定义ImageView
  private speakImageView;
  speakImageView = findViewById(R.id.speak1);
  // set onClick listener
  speakImageView.setOnClickListener(this);
  • 然后在 onClick 方法下,如果遇到特定字母,我会定义播放该字母的声音。我使用了mp3 声音文件,因为我无法实现TTS,所以我选择使用mp3
@Override
  public void onClick(View v) {
   // some code
    ...
    // voice for the detected alphabet
    else if (v.getId() == R.id.speak1) {
      // this is the value we are showing
      EditText mEdit = findViewById(R.id.editText);
      String letter = mEdit.getText().toString();
      if (letter.equalsIgnoreCase("A")) {
        final MediaPlayer mp100 = MediaPlayer.create(this, R.raw.letter_a);
        mp100.start();
      }
      else if (letter.equalsIgnoreCase("B")) {
        final MediaPlayer mp100 = MediaPlayer.create(this, R.raw.letter_b);
        mp100.start();
      }
      // similarly you can do the same for other alphabets also
    }
  }
  • 不是理想的方法,但由于 ```TTS`` 对我不起作用,所以在几乎搜索了一周或 2 周后才使用此方法,因为我是 android 新手。

【讨论】:

    猜你喜欢
    • 2012-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多