Example usage for android.speech.tts TextToSpeech ERROR

List of usage examples for android.speech.tts TextToSpeech ERROR

Introduction

In this page you can find the example usage for android.speech.tts TextToSpeech ERROR.

Prototype

int ERROR

To view the source code for android.speech.tts TextToSpeech ERROR.

Click Source Link

Document

Denotes a generic operation failure.

Usage

From source file:info.jmfavreau.bifrostgears.BifrostGears.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FuzzyColorRules.load(this);
    SemanticColorRules.load(this, "standard");
    setContentView(R.layout.activity_bifrostgears);

    Button button = (Button) findViewById(R.id.speech_button);
    button.setOnClickListener(new View.OnClickListener() {
        @Override// w ww .j a v a2  s . com
        public void onClick(View v) {
            DoIt(v);
        }
    });

    textToSpeech = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
        @Override
        public void onInit(int status) {
            if (status != TextToSpeech.ERROR) {
                textToSpeech.setLanguage(Locale.getDefault());
            }
        }
    });

}

From source file:com.rstar.mobile.simpledemos.InvisibleFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mMessage = getArguments().getString(EXTRA_message);

    mTextToSpeech = new TextToSpeech(getActivity().getApplicationContext(), new TextToSpeech.OnInitListener() {
        @Override/*from w w w . j  a v  a 2  s  . com*/
        public void onInit(int status) {
            if (status != TextToSpeech.ERROR) {
                mTextToSpeech.setLanguage(Locale.ENGLISH);
                // When the fragment is just created, wait for TTS to set up before speaking.
                startSpeaking();
            }
        }
    });
    setRetainInstance(true);
}

From source file:com.ibm.mobilefirst.mobileedge.recordapp.TestingActivity.java

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

    detectedGesture = (TextView) findViewById(R.id.detectedGesture);
    score = (TextView) findViewById(R.id.scoring);

    detectedLayout = findViewById(R.id.detectedLayout);
    sensingLayout = findViewById(R.id.sensingLayout);

    getSupportActionBar().setTitle(R.string.testing_title);

    RecordApplication application = (RecordApplication) getApplication();
    controller = application.controller;

    textToSpeech = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
        @Override//from w w  w .ja  va2s.  c  o  m
        public void onInit(int status) {
            if (status != TextToSpeech.ERROR) {
                textToSpeech.setLanguage(Locale.US);
            }
        }
    });
}

From source file:com.mobile.lapa.waitandsee.MainActivity.java

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

    mRegistrationProgressBar = (ProgressBar) findViewById(R.id.registrationProgressBar);
    mRegistrationBroadcastReceiver = new BroadcastReceiver() {
        @Override//from   w  w  w .  j a va 2s. c o  m
        public void onReceive(Context context, Intent intent) {
            mRegistrationProgressBar.setVisibility(ProgressBar.GONE);
            SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
            boolean sentToken = sharedPreferences.getBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false);
            if (!sentToken) {
                mMessageTextView.setText(getString(R.string.token_error_message));
            }
        }
    };

    mMessageTextView = (TextView) findViewById(R.id.messageTextView);
    mTitleTextView = (TextView) findViewById(R.id.titleTextView);
    mUserNameEditText = (EditText) findViewById(R.id.userNameEditText);
    mSubmitButton = (Button) findViewById(R.id.submitButton);

    mUserNameEditText.setOnEditorActionListener(new EditText.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                mSubmitButton.performClick();
                return true;
            }
            return false;
        }
    });

    if (this.textToSpeech == null) {
        textToSpeech = new TextToSpeech(this.getApplicationContext(), new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(int status) {
                if (status != TextToSpeech.ERROR) {
                    textToSpeech.setLanguage(Locale.ENGLISH); //getDefault());
                }
            }
        });
    }

    Bundle b = getIntent().getExtras();
    String title = "";
    String message = "";
    if (b != null) {
        title = b.getString("TITLE_KEY");
        message = b.getString("MESSAGE_KEY");
    }

    if (title == "" && message == "") { //(b == null) {
        mTitleTextView.setText(getString(R.string.welcome_title));
        mMessageTextView.setText(getString(R.string.welcome_message));
    } else {
        mTitleTextView.setText(title);
        mMessageTextView.setText(message);
        playSound(title);
    }

    if (checkPlayServices()) {
        // Start IntentService to register this application with GCM.
        Intent intent = new Intent(this, RegistrationIntentService.class);
        startService(intent);
    }
    // ------- User name ------------
    settings = getSharedPreferences("PREF_NAME", Context.MODE_PRIVATE);
    userName = settings.getString("USER_NAME", "");
    if (userName != "") {
        // user name already set
        hideUserFields();
    }
    setUserTitle();
}

From source file:com.vyasware.vaani.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    returnedText = (TextView) findViewById(R.id.textView1);
    outputText = (TextView) findViewById(R.id.textView2);
    progressBar = (ProgressBar) findViewById(R.id.progressBar1);
    toggleButton = (ToggleButton) findViewById(R.id.toggleButton1);

    progressBar.setVisibility(View.INVISIBLE);
    speech = SpeechRecognizer.createSpeechRecognizer(this);
    speech.setRecognitionListener(this);
    recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    //        recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE,
    //                "en");
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, this.getPackageName());
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "hi-IN");
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "hi-IN");
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE, "hi-IN");
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5);
    tts = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
        @Override//from  ww  w. j av  a2  s . com
        public void onInit(int status) {
            if (status != TextToSpeech.ERROR) {
                tts.setLanguage(new Locale("hi_IN"));
                tts.setSpeechRate(0.9f);
            }
        }
    });
    returnedText.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
            intent.putExtra(SearchManager.QUERY, returnedText.getText());
            if (intent.resolveActivity(getPackageManager()) != null)
                startActivity(intent);

        }
    });

    toggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                progressBar.setVisibility(View.VISIBLE);
                progressBar.setIndeterminate(true);
                speech.startListening(recognizerIntent);
                outputText.setText("");
            } else {
                progressBar.setIndeterminate(false);
                progressBar.setVisibility(View.INVISIBLE);
                speech.stopListening();
            }
        }
    });

}

From source file:onion.chat.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    db = Database.getInstance(this);
    tor = Tor.getInstance(this);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from   w ww  . j a  v  a 2 s. c o m
    t1 = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
        @Override
        public void onInit(int status) {
            if (status != TextToSpeech.ERROR) {
                t1.setLanguage(Locale.US);
            }
        }
    });
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            final Dialog[] d = new Dialog[1];

            View v = getLayoutInflater().inflate(R.layout.dialog_connect, null);
            ((TextView) v.findViewById(R.id.id)).setText(Tor.getInstance(MainActivity.this).getID());
            v.findViewById(R.id.qr_show).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    d[0].cancel();
                    showQR();
                }
            });
            v.findViewById(R.id.qr_scan).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    d[0].cancel();
                    scanQR();
                }
            });
            v.findViewById(R.id.enter_id).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    d[0].cancel();
                    addContact();
                }
            });
            v.findViewById(R.id.share_id).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    d[0].cancel();
                    inviteFriend();
                }
            });
            d[0] = new AlertDialog.Builder(MainActivity.this)
                    //.setTitle(R.string.add_contact)
                    .setView(v).show();

        }
    });

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    startService(new Intent(this, HostService.class));

    findViewById(R.id.myname).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            changeName();
        }
    });

    findViewById(R.id.myaddress).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showQR();
        }
    });

    contactPage = getLayoutInflater().inflate(R.layout.page_contacts, null);
    requestPage = getLayoutInflater().inflate(R.layout.page_requests, null);

    contactRecycler = (RecyclerView) contactPage.findViewById(R.id.contactRecycler);
    requestRecycler = (RecyclerView) requestPage.findViewById(R.id.requestRecycler);

    contactEmpty = contactPage.findViewById(R.id.contactEmpty);
    requestEmpty = requestPage.findViewById(R.id.requestEmpty);

    contactRecycler.setLayoutManager(new LinearLayoutManager(this));
    contactRecycler.setAdapter(new RecyclerView.Adapter<ContactViewHolder>() {
        @Override
        public ContactViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            final ContactViewHolder viewHolder = new ContactViewHolder(
                    getLayoutInflater().inflate(R.layout.item_contact, parent, false));
            viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String toSpeak = viewHolder.name.getText().toString();
                    Toast.makeText(getApplicationContext(), toSpeak, Toast.LENGTH_SHORT).show();
                    t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
                    startActivity(
                            new Intent(Intent.ACTION_VIEW, Uri.parse("chat:" + viewHolder.address.getText()),
                                    getApplicationContext(), ChatActivity.class));
                }
            });
            viewHolder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    contactLongPress(viewHolder.address.getText().toString(),
                            viewHolder.name.getText().toString());
                    return true;
                }
            });
            return viewHolder;
        }

        @Override
        public void onBindViewHolder(ContactViewHolder holder, int position) {
            contactCursor.moveToPosition(position);
            holder.address.setText(contactCursor.getString(0));
            String name = contactCursor.getString(1);
            if (name == null || name.equals(""))
                name = "Anonymous";
            holder.name.setText(name);
            long n = contactCursor.getLong(2);
            if (n > 0) {
                holder.badge.setVisibility(View.VISIBLE);
                holder.count.setText("" + n);
            } else {
                holder.badge.setVisibility(View.GONE);
            }
        }

        @Override
        public int getItemCount() {
            return contactCursor != null ? contactCursor.getCount() : 0;
        }
    });

    requestRecycler.setLayoutManager(new LinearLayoutManager(this));
    requestRecycler.setAdapter(new RecyclerView.Adapter<ContactViewHolder>() {
        @Override
        public ContactViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            final ContactViewHolder viewHolder = new ContactViewHolder(
                    getLayoutInflater().inflate(R.layout.item_contact_request, parent, false));
            viewHolder.accept.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String addr = viewHolder.address.getText().toString();
                    db.acceptContact(addr);
                    Client.getInstance(getApplicationContext()).startAskForNewMessages(addr);
                    updateContactList();
                }
            });
            viewHolder.decline.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    final String address = viewHolder.address.getText().toString();
                    final String name = viewHolder.name.getText().toString();
                    db.removeContact(address);
                    updateContactList();
                    Snackbar.make(findViewById(R.id.drawer_layout), R.string.contact_request_declined,
                            Snackbar.LENGTH_LONG).setAction(R.string.undo, new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    db.addContact(address, false, true, name);
                                    updateContactList();
                                }
                            }).show();
                }
            });
            return viewHolder;
        }

        @Override
        public void onBindViewHolder(ContactViewHolder holder, int position) {
            requestCursor.moveToPosition(position);
            holder.address.setText(requestCursor.getString(0));
            String name = requestCursor.getString(1);
            if (name == null || name.equals(""))
                name = "Anonymous";
            holder.name.setText(name);
        }

        @Override
        public int getItemCount() {
            return requestCursor != null ? requestCursor.getCount() : 0;
        }
    });

    tabLayout = (TabLayout) findViewById(R.id.tabLayout);

    final ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
    viewPager.setAdapter(new PagerAdapter() {
        @Override
        public int getCount() {
            return 2;
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public Object instantiateItem(final ViewGroup container, int position) {
            View v = position == 0 ? contactPage : requestPage;
            container.addView(v);
            return v;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }
    });
    tabLayout.setupWithViewPager(viewPager);

    tabLayout.getTabAt(0).setText(R.string.tab_contacts);
    tabLayout.getTabAt(1).setText(R.string.tab_requests);

    for (int i = 0; i < 2; i++) {
        View v = getLayoutInflater().inflate(R.layout.tab_header, null, false);
        ((TextView) v.findViewById(R.id.text)).setText(tabLayout.getTabAt(i).getText().toString());
        ((TextView) v.findViewById(R.id.badge)).setText("");
        v.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        tabLayout.getTabAt(i).setCustomView(v);
    }

    tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            if (tab.getPosition() == 1) {
                db.clearNewRequests();
            }
            viewPager.setCurrentItem(tab.getPosition());
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {
        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {
        }
    });
    updateContactList();

    handleIntent();
    //  inform();
    listen();
}

From source file:baasi.hackathon.sja.TalkActivity.java

/**
 * ?? ???//from  w w w .jav a 2s.  c om
 * @param word String
 */
private void startTalk(final String word) {
    speech = new TextToSpeech(getBaseContext(), new TextToSpeech.OnInitListener() {
        @Override
        public void onInit(int status) {
            if (status != TextToSpeech.ERROR) {
                speech.setLanguage(Locale.UK);
                speech.speak(word, TextToSpeech.QUEUE_FLUSH, null);
            }
        }
    });
}

From source file:com.ct.speech.TTS.java

/**
 * Called when the TTS service is initialized.
 * //from   www .  jav a  2 s  .co  m
 * @param status 
 */
public void onInit(int status) {
    if (status == TextToSpeech.SUCCESS) {
        state = TTS.STARTED;
        PluginResult result = new PluginResult(PluginResult.Status.OK, TTS.STARTED);
        result.setKeepCallback(false);
        this.success(result, this.startupCallbackId);
    } else if (status == TextToSpeech.ERROR) {
        state = TTS.STOPPED;
        PluginResult result = new PluginResult(PluginResult.Status.ERROR, TTS.STOPPED);
        result.setKeepCallback(false);
        this.error(result, this.startupCallbackId);
    }
}

From source file:treehou.se.habit.gcm.GcmIntentService.java

private void sendNotification(final String msg, int notificationId) {
    if (mNotificationManager == null) {
        mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    }// w w w .  j  a  v a 2s .  co m

    Intent notificationIntent = new Intent(this, MainActivity.class);
    notificationIntent.setAction("org.openhab.notification.selected");
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra("notificationId", notificationId);

    PendingIntent pendingNotificationIntent = PendingIntent.getActivity(getApplicationContext(), 0,
            notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    // Check if notification should be spoken

    Log.d(TAG, "Message " + Constants.PREF_REGISTRATION_SERVER + notificationId);

    /*getSharedPreferences(Constants.PREF_REGISTRATION_SERVER + notificationId, MODE_PRIVATE);
    SharedPreferences preferences = getSharedPreferences(Constants.PREFERENCE_SERVER, Context.MODE_PRIVATE);
    long serverId = preferences.getLong(Constants.PREF_REGISTRATION_SERVER+notificationId,-1);
            
    if(serverId < 0){
    return;
    }
            
    Server server = Server.load(Server.class, serverId);*/

    NotificationSettingsDB notificationSettings = NotificationSettingsDB.loadGlobal(getApplicationContext());
    if (notificationSettings.notificationToSpeach()) {
        textToSpeech = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(int status) {
                if (status != TextToSpeech.ERROR) {
                    textToSpeech.setLanguage(Locale.getDefault());
                    textToSpeech.speak(msg, TextToSpeech.QUEUE_FLUSH, null);
                }
            }
        });
    }

    /*NotificationDB notification = new NotificationDB(msg);
    notification.save();
    List<NotificationDB> notifications = new Select().all().from(NotificationDB.class).execute();*/
    //TODO create inbox style

    String replyLabel = getString(R.string.notification_title);
    RemoteInput remoteInput = new RemoteInput.Builder(VoiceActionService.EXTRA_VOICE_REPLY).setLabel(replyLabel)
            .build();

    Intent replyIntent = new Intent(this, VoiceActionService.class);
    PendingIntent replyPendingIntent = PendingIntent.getService(this, 0, replyIntent, 0);

    // Create the reply action and add the remote input
    NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.action_voice_light,
            getString(R.string.voice_command), replyPendingIntent).addRemoteInput(remoteInput).build();

    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_notification).setContentTitle(getString(R.string.notification_title))
            .setAutoCancel(true).setSound(alarmSound)
            .extend(new NotificationCompat.WearableExtender().addAction(action)).setContentText(msg);

    mBuilder.setContentIntent(pendingNotificationIntent);

    mNotificationManager.notify(notificationId, mBuilder.build());
}

From source file:me.hammarstrom.imagerecognition.activities.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    bindViews();//from   ww  w  .  j a  v a2s.  co  m

    mToolbar.setTitle("");
    setSupportActionBar(mToolbar);
    mCameraPreviewLayout.setOnClickListener(this);
    mButtonReset.setOnClickListener(this);

    //        mGestureDetector = new GestureDetectorCompat(this, new CameraPreviewGestureListener());
    //        mCameraPreviewLayout.setOnTouchListener(new View.OnTouchListener() {
    //            @Override
    //            public boolean onTouch(View v, MotionEvent event) {
    //                return mGestureDetector.onTouchEvent(event);
    //            }
    //        });

    mTts = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {

        @Override
        public void onInit(int status) {
            if (status != TextToSpeech.ERROR) {
                mTts.setLanguage(Locale.UK);
            }
        }
    });
}