1. You want that $100.00 in your pocket or an Amazon Fire TV don't you? Well here's the deal. With our new updated look we are in desperate need of an updated logo. The 'old' one has certainly served us well, but it's time. Find all the details here: bit.ly/1q0k6Wa
  2. DroidForums.net is currently undergoing a major software upgrade. If you are experiencing any problems logging in please: Contact Us

Need help with tts

Discussion in 'Android App Developers' started by kraxyk, Oct 29, 2010.

  1. kraxyk
    Offline

    kraxyk New Member

    Joined:
    Feb 8, 2010
    Messages:
    74
    Likes Received:
    0
    Trophy Points:
    0
    Hello, I am trying to get tts working in my app. I have read a lot of material but I still don't understand what to do. I imported the tts resource and created a mytts variable using this code. Thats all I've gotten to work.

    Code:
    TextToSpeech mytts = new TextToSpeech(this,this)
    but it also doesn't understand this,this

    maybe a good step by step tutorial would help
  2. kraxyk
    Offline

    kraxyk New Member

    Joined:
    Feb 8, 2010
    Messages:
    74
    Likes Received:
    0
    Trophy Points:
    0
    Ok so this is the code I have so far following a tutorial I found here Click Me

    I am still getting errors
    Code:
    package com.kmccmk9.CarVoice;
    
    import android.app.Activity;
    import android.content.Intent;
    import android.widget.TextView;
    import android.os.Bundle;
    import android.speech.tts.*;
    
    public class CarVoice extends Activity implements OnInitListener {
        /** Called when the activity is first created. */
       private TextToSpeech tts;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            TextView lbl_tv = new TextView(this);
            lbl_tv.setText("Welcome to Car Voice. This app was designed for you to never have to use your hand for your phone while you are in the car.");
            lbl_tv.setTextSize(28);
            setContentView(lbl_tv);
            
            Intent checkIntent = new Intent();
            checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
            startActivityForResult(checkIntent, 0);
            tts = new TextToSpeech(this, this);
    
        }       
        @Override
        public void onInit(int arg0) {
            // TODO Auto-generated method stub
            String speech1 = "How are you?";
            String speech2 = "I hope you are fine.";
            tts.setLanguage(Locale.US);
            tts.speak(speech1, TextToSpeech.QUEUE_FLUSH, null);
            tts.speak(speech2, TextToSpeech.QUEUE_ADD, null);
        }
    
    
    
    }