2014-04-15 22 views
5

Konuşma tanıma sırasında "Dialog" u özelleştirmeye çalışıyorum. enter image description hereAndroid Özel Ses Tanıma GUI İletişim kutusu

Doğru anlıyorsam, yukarıdaki görüntüdeki konuşma tanıma GUI'sini özelleştirmek için SpeechRecognizer kullanmam gerekiyor.

Bu How to get audio amplitude with speech recognizer?, soruma benzer, ancak o zaten tanıma oluyor ise, kullanışlı olmasına rağmen bu yüzden onun sorusunu yeni GUI nasıl uygulanacağı anladım beri, onRmsChanged kullanılarak genlik göstergesi ekleme hakkında soruyor, biraz daha ileride Im'de.

Bu örnek özel UI'nin nasıl uygulandığını açıklayan örnek projeler var mı? ApiDemo VoiceRecognition örneğine baktım ama hala UI ayarını/değiştirileceği yeri görmüyorum. Bu nedenle, sözde yaklaşım, Dialog'u genişleten ve RecognitionListener'ı uygulayan bir SpeechDialogClass, bir iletişim sınıfı oluşturmak olacaktır. Böyle bir şey. Yöntemleri bir yere bağlamı, onRmsChanged teslim vb. Ayarlayacağını hayal ediyorum ama oradan çok fazla kayıp oldum.

public class SpeechDialogClass extends Dialog implements RecognitionListener { 

    public Activity c; 
    public Dialog d; 
    public ImageView mic, mic_amp; 

    public SpeechDialogClass(Activity a) { 
     super(a); 
     // TODO Auto-generated constructor stub 
     this.c = a; 
    } 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     setContentView(R.layout.speech_dialog_kids); 
     mic = (ImageView) findViewById(R.id.mic_icon); 
     mic_amp = (ImageView) findViewById(R.id.speech_amplitude); 

     // //So I would set some sort of listener to change the selector state 
     // of mic_icon and the 
     // /somewhere I would set the mic_amp to listen/ract to on onRmsChanged 
     // public void onRmsChanged(float arg0)/// 
     // // and this is where Im lost/// 

    } 

    public void onBeginningOfSpeech() { 
     // TODO Auto-generated method stub 
     setContentView(R.layout.speech_dialog_kids); 
    } 

    public void onBufferReceived(byte[] arg0) { 
     // TODO Auto-generated method stub 

    } 

    public void onEndOfSpeech() { 
     // TODO Auto-generated method stub 

    } 

    public void onError(int arg0) { 
     // TODO Auto-generated method stub 

    } 

    public void onEvent(int arg0, Bundle arg1) { 
     // TODO Auto-generated method stub 

    } 

    public void onPartialResults(Bundle arg0) { 
     // TODO Auto-generated method stub 

    } 

    public void onReadyForSpeech(Bundle arg0) { 
     // TODO Auto-generated method stub 

    } 

    public void onResults(Bundle arg0) { 
     // TODO Auto-generated method stub 

    } 

    public void onRmsChanged(float arg0) { 
     // TODO Auto-generated method stub 
     // pseudo code// 
     // mic_amp.doSomething(and a float); 
    } 

} 

Benim speech_dialiog_kids.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="150dp" 
    android:background="#3E80B4" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/txt_dia" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_margin="10dp" 
     android:text="Speak Text" 
     android:textColor="@android:color/white" 
     android:textSize="15dp" 
     android:textStyle="bold" > 
    </TextView> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:background="#3E80B4" 
     android:orientation="horizontal" > 

     <ImageView 
      android:id="@+id/speech_amplitude" 
      android:layout_width="78dp" 
      android:layout_height="78dp" 
      android:layout_marginTop="10dp" 
      android:src="@drawable/amplitude_icon" 
      android:visibility="visible" /> 

     <ImageView 
      android:id="@+id/mic_icon" 
      android:layout_width="68dp" 
      android:layout_height="68dp" 
      android:layout_marginLeft="-73dp" 
      android:layout_marginTop="16dp" 
      android:src="@drawable/small_right_grey_white" 
      android:visibility="visible" /> 
    </LinearLayout> 

</LinearLayout> 

enter image description here

cevap

1
ben bağlamı, vb onRmsChanged teslimini kuracak yöntemlerinde olduğu bir yere hayal ediyorum .. ama oradan Im hemen hemen kaybolmuş

. Böyle

şey:

public void onRmsChanged(float rms) { 
    if (rms < limit1) 
     mic_amp.setImageResource(1); 
    else if (rms < limit2) 
     mic_amp.setImageResource(2); 
    else if (rms < limit3) 
     mic_amp.setImageResource(3); 
} 

Yani rms değişime palslayacaktır. Görüntüyü rms seviyesine bağlı olarak değiştirirsiniz. Gerçek resmi değiştirmek için çeşitli ImageView yöntemini değiştirebilirsiniz.

Başka bir sorun da, Android sürümüne bağlı olarak her zaman onRmsChanged çağrılmamasıdır, bu nedenle bu özelliği uygulamak zorlaşır. O zaman muhtemelen en kolay yol orijinal diyalogda kalmaktır.

+0

Yardımlarınız için çok teşekkürler. Bunu deneyeceğim. "Başka bir sorun, onRmsChanged'in her zaman Android sürümüne bağlı olarak çalıştırılmamasıdır" Evet bunu da okudum, neden böyle olacağını merak ediyorum. Tekrar teşekkürler – Mcorv

+0

Google, motorlarını yeniden markalamanıza izin vermek istemediği için. –

İlgili konular