Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
public void setGoVisible(boolean visibility)
{
this.runOnUiThread(new Runnable()
{
@Override
public void run()
{
MainActivity.this.btn_go.setVisibility( visibility ? View.VISIBLE : View.INVISIBLE );
}
});
}
ttsIdentifier.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, UUID.randomUUID().toString());
tts.speak("11111111", TextToSpeech.QUEUE_FLUSH, ttsIdentifier);
package de.vollkanone.sprachhilfe;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;
import java.util.UUID;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity implements OnInitListener{
Button btn_go;
TextView tw;
private TextToSpeech tts;
HashMap<String, String> ttsIdentifier = new HashMap<String, String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tts = new TextToSpeech(this, this);
btn_go = (Button) findViewById(R.id.btn_go);
btn_go.setVisibility(View.INVISIBLE);
tw = (TextView) findViewById(R.id.textView1);
btn_go.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//button("btn_go");
tw.setText("111111111");
tts.speak("11111111", TextToSpeech.QUEUE_FLUSH, null);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void button(String btn) {
if(btn.equalsIgnoreCase("btn_go")) {
erkennen(this);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == SPEECH_RECOGNIZED) {
if(data != null) {
ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
if(!result.isEmpty()) {
tw.setText(result.get(0));
ttsIdentifier.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, UUID.randomUUID().toString());
tts.speak("11111111", TextToSpeech.QUEUE_FLUSH, ttsIdentifier);
}
}
}
}
static public final int SPEECH_RECOGNIZED = 1;
static public void erkennen(Activity activity) {
Intent intent = new Intent();
intent.setAction(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
activity.startActivityForResult(intent, SPEECH_RECOGNIZED);
}
@Override
public void onInit(int status) {
tts.setLanguage(Locale.GERMAN);
tts.setSpeechRate((float) 1.5);
//btn_go.setVisibility(View.VISIBLE);
MainActivity.this.btn_go.setVisibility(View.VISIBLE);
tts.setOnUtteranceProgressListener(new MyUtteranceProgressListener(this));
}
public void setGoVisible(final boolean visibility)
{
this.runOnUiThread(new Runnable()
{
@Override
public void run()
{
MainActivity.this.btn_go.setVisibility( visibility ? View.VISIBLE : View.INVISIBLE );
}
});
}
}
btn_go.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//button("btn_go");
tw.setText("111111111");
ttsIdentifier.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, UUID.randomUUID().toString());
tts.speak("11111111", TextToSpeech.QUEUE_FLUSH, ttsIdentifier);
}
});