List of usage examples for android.speech SpeechRecognizer createSpeechRecognizer
public static SpeechRecognizer createSpeechRecognizer(final Context context, final ComponentName serviceComponent)
From source file:com.baidu.android.voicedemo.ActivityTouch.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.sdk2_api);/*from ww w. j a va 2s . c o m*/ txtResult = (TextView) findViewById(R.id.txtResult); txtLog = (TextView) findViewById(R.id.txtLog); btn = (Button) findViewById(R.id.btn); setting = (Button) findViewById(R.id.setting); setting.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent("com.baidu.speech.asr.demo.setting"); startActivity(intent); } }); speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this, new ComponentName(this, VoiceRecognitionService.class)); speechRecognizer.setRecognitionListener(this); speechTips = View.inflate(this, R.layout.bd_asr_popup_speech, null); speechWave = speechTips.findViewById(R.id.wave); speechTips.setVisibility(View.GONE); addContentView(speechTips, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); btn.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: speechTips.setVisibility(View.VISIBLE); speechRecognizer.cancel(); Intent intent = new Intent(); bindParams(intent); intent.putExtra("vad", "touch"); txtResult.setText(""); txtLog.setText(""); speechRecognizer.startListening(intent); return true; case MotionEvent.ACTION_UP: speechRecognizer.stopListening(); speechTips.setVisibility(View.GONE); break; } return false; } }); }
From source file:com.baidu.android.voicedemo.ApiActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.sdk2_api);// w ww .j a v a 2 s . c om txtResult = (TextView) findViewById(R.id.txtResult); txtLog = (TextView) findViewById(R.id.txtLog); btn = (Button) findViewById(R.id.btn); setting = (Button) findViewById(R.id.setting); speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this, new ComponentName(this, VoiceRecognitionService.class)); speechRecognizer.setRecognitionListener(this); setting.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent("com.baidu.speech.asr.demo.setting"); startActivity(intent); } }); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(ApiActivity.this); boolean api = sp.getBoolean("api", false); if (api) { switch (status) { case STATUS_None: start(); btn.setText("?"); status = STATUS_WaitingReady; break; case STATUS_WaitingReady: cancel(); status = STATUS_None; btn.setText(""); break; case STATUS_Ready: cancel(); status = STATUS_None; btn.setText(""); break; case STATUS_Speaking: stop(); status = STATUS_Recognition; btn.setText(""); break; case STATUS_Recognition: cancel(); status = STATUS_None; btn.setText(""); break; } } else { start(); } } }); }
From source file:com.chexiaoya.gaodemapdemo.SpeechSearchActivity.java
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.search_activity_layout); ButterKnife.bind(this); speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this, new ComponentName(this, VoiceRecognitionService.class)); speechRecognizer.setRecognitionListener(this); getDatas();/*from w w w . j a v a 2 s. co m*/ /** ? */ mResultText.addTextChangedListener(this); }
From source file:cn.laojing.smarthome.VoiceActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.voice);//from w w w. ja va2 s . c o m setListAdapter(mListViewAdapter); speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this, new ComponentName(this, VoiceRecognitionService.class)); speechRecognizer.setRecognitionListener(this); initialEnv(); initialTts(); mSpeechSynthesizer.speak("?"); mVoiceControl = new VoiceControl(this, mSpeechSynthesizer); imgBtn = (ImageView) findViewById(R.id.imageView); imgBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { start(); } }); Intent bindIntent = new Intent(this, CommandService.class); bindService(bindIntent, connection, BIND_AUTO_CREATE); //start(); }
From source file:com.ppdl.microphone.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); sp.edit().remove(Constant.EXTRA_INFILE).commit(); // infile?PCM????? Button recordButton = (Button) findViewById(R.id.buttonRecord); recordButton.setOnTouchListener(new View.OnTouchListener() { @Override//from w w w . jav a2s . c o m public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: startRecording(); Toast.makeText(MainActivity.this, "Start Recording", Toast.LENGTH_SHORT).show(); break; case MotionEvent.ACTION_UP: stopRecording(); v.performClick(); Toast.makeText(MainActivity.this, "Stop Recording", Toast.LENGTH_SHORT).show(); break; default: break; } return false; } }); Button playButton = (Button) findViewById(R.id.buttonPlay); playButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startPlaying(); } }); Button stopButton = (Button) findViewById(R.id.buttonStop); stopButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { stopPlaying(); } }); Button recognizeButton = (Button) findViewById(R.id.buttonRecognize); recognizeButton.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: Toast.makeText(MainActivity.this, "Start Recognizing", Toast.LENGTH_SHORT).show(); speechRecognizer.cancel(); Intent intent = new Intent(); bindParams(intent); intent.putExtra("vad", "touch"); speechRecognizer.startListening(intent); break; case MotionEvent.ACTION_UP: v.performClick(); Toast.makeText(MainActivity.this, "Stop Recognizing", Toast.LENGTH_SHORT).show(); speechRecognizer.stopListening(); break; default: break; } return false; } }); speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this, new ComponentName(this, VoiceRecognitionService.class)); speechRecognizer.setRecognitionListener(mRecognitionListner); }
From source file:com.onebus.view.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Log.i("MainActivity", "OnCreate"); speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this, new ComponentName(this, VoiceRecognitionService.class)); speechRecognizer.setRecognitionListener(this); mStationList = new ArrayList<HashMap<String, Object>>(); try {//ww w . j a va 2s .co m initMap(); initWidget(); // ? initOritationListener(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.example.haizhu.myvoiceassistant.ui.RobotChatActivity.java
private void iniData() { globalPref = GlobalPref.getInstance(); TruingDataHandler.setListener(this); chatAdapter = new RobotChatAdapter(getApplicationContext(), resultList); initListener();// w ww. j ava 2 s . c o m speechRecognizer = SpeechRecognizer.createSpeechRecognizer(getApplicationContext(), new ComponentName(this, VoiceRecognitionService.class)); speechRecognizer.setRecognitionListener(recognitionListener); speechSynthesizer = new SpeechSynthesizer(AssistantApplication.getInstance().getApplicationContext(), "holder", speechSynthesizerListener); // ?setApiKey???apiKeysecretKey speechSynthesizer.setApiKey("DnBhRg9PvmNSs0a6OD4BHLAk", "8492ef7b1b435bce2b98e41c1023e67b"); speechSynthesizer.setAudioStreamType(AudioManager.STREAM_MUSIC); listener = new DrawerLayout.DrawerListener() { @Override public void onDrawerSlide(View drawerView, float slideOffset) { } @Override public void onDrawerOpened(View drawerView) { } @Override public void onDrawerClosed(View drawerView) { } @Override public void onDrawerStateChanged(int newState) { } }; }
From source file:cn.jasonlv.siri.activity.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // ??? ???/* ww w . j a v a 2 s . co m*/ musicManager = new MusicManager(getApplicationContext()); // ?? initImageLoader(getApplicationContext()); /* get the installed package list*/ // ?? mPackageManager = new NativePackageManager(getApplicationContext()); // ? setVolumeControlStream(AudioManager.STREAM_MUSIC); // ? mSynthesizer = new Synthesizer(getApplicationContext()); //mSynthesizer.speak("EDI"); // ? mContactManager = new ContactsManager(getApplicationContext()); mContactManager.getContactList(); // ?? detactor = new LocationDetactor(getApplicationContext()); info = detactor.getLocationInfo(); Log.d("location info", info.lat + ", " + info.lon); //for(Object o : mPackageManager.getPackageList()){ // System.out.println(o.toString()); setContentView(R.layout.sdk2_api); //txtLog = (TextView) findViewById(R.id.txtLog); btn = (ActionButton) findViewById(R.id.btn); // ? speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this, new ComponentName(this, VoiceRecognitionService.class)); speechRecognizer.setRecognitionListener(this); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(MainActivity.this); boolean api = sp.getBoolean("api", false); if (api) { switch (status) { case STATUS_None: start(); //btn.setText("?"); status = STATUS_WaitingReady; break; case STATUS_WaitingReady: cancel(); status = STATUS_None; //btn.setText(""); break; case STATUS_Ready: cancel(); status = STATUS_None; //btn.setText(""); break; case STATUS_Speaking: stop(); status = STATUS_Recognition; //btn.setText(""); break; case STATUS_Recognition: cancel(); status = STATUS_None; //btn.setText(""); break; } } else { start(); } } }); ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); actionBar.setDisplayShowTitleEnabled(true); container = (LinearLayout) findViewById(R.id.container); scrollView = (ScrollView) findViewById(R.id.scroll); scrollView.fullScroll(View.FOCUS_DOWN); }
From source file:com.cwp.cmoneycharge.activity.AddPayActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.add);// SysApplication.getInstance().addActivity(this); // ?this super.onStart();// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setTranslucentStatus(true);/*from w w w . j av a 2s .co m*/ findViewById(R.id.top).setVisibility(View.VISIBLE); } mTintManager = new SystemBarTintManager(this); mTintManager.setStatusBarTintEnabled(true); mTintManager.setStatusBarTintResource(R.color.statusbar_bg); txtMoney = (EditText) findViewById(R.id.txtMoney);// ?? txtTime = (EditText) findViewById(R.id.txtTime);// ? txtAddress = (EditText) findViewById(R.id.txtAddress);// ? txtMark = (EditText) findViewById(R.id.txtMark);// ? spType = (Spinner) findViewById(R.id.spType);// ? btnSaveButton = (Button) findViewById(R.id.btnSave);// ?? btnCancelButton = (Button) findViewById(R.id.btnCancel);// ?? btnVoice = (Button) findViewById(R.id.btnVoice);// ? rb1 = (RadioButton) findViewById(R.id.payout_tab_rb); rb2 = (RadioButton) findViewById(R.id.income_tab_rb); left_back = (ImageView) findViewById(R.id.example_left3); btn_loacte = (ImageView) findViewById(R.id.btn_loacte); addphoto = (ImageView) findViewById(R.id.addphoto); bottom_empty = (FrameLayout) findViewById(R.id.bottom_empty); bottom_full = (LinearLayout) findViewById(R.id.bottom_full); //? //? mLocationClient = new LocationClient(getApplicationContext()); mLocationClient.registerLocationListener(mLocationListener); //TODO speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this, new ComponentName(this, VoiceRecognitionService.class)); speechRecognizer.setRecognitionListener(this); dialogShowUtil = new DialogShowUtil(this, this, VoiceSave, type, // ?dialog VoiceDefault); btn_loacte.setOnClickListener(this); // ? // ???? bottom_empty.setOnClickListener(new OnClickListener() { public void onClick(View v) { keyBoard.hideKeyboard(); bottom_empty.setVisibility(View.GONE); bottom_full.setVisibility(View.VISIBLE); } }); // addphoto.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(AddPayActivity.this, PublishedActivity.class); intent.putExtra("cwp.id", userid); startActivityForResult(intent, 102); } }); left_back.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = null; type = "pay"; typemode = "add"; if (bundle.containsKey("cwp.frament3")) { intent = new Intent(AddPayActivity.this, MainActivity.class); intent.putExtra("cwp.Fragment", "3");// ? } else { intent = new Intent(AddPayActivity.this, MainActivity.class); } intent.putExtra("cwp.id", userid); startActivity(intent); finish();// } }); // mRecognitionListener = new DialogRecognitionListener() { // ? // // @Override // public void onResults(Bundle results) { // ArrayList<String> rs = results != null ? results // .getStringArrayList(RESULTS_RECOGNITION) : null; // if (rs != null && rs.size() > 0) { // Recognition(rs.get(0)); // ? // // Toast.makeText(AddPayActivity.this, rs.get(0), // // Toast.LENGTH_SHORT).show(); // } // } // }; corporation_fl = (FrameLayout) findViewById(R.id.corporation_fl); address_fl = (FrameLayout) findViewById(R.id.address_fl); //checkBox rb1.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (rb1.isChecked()) { // type = "pay"; } else // { type = "income"; } updatetype(); } }); final Calendar c = Calendar.getInstance();// ?? mYear = c.get(Calendar.YEAR);// ? mMonth = c.get(Calendar.MONTH);// ? mDay = c.get(Calendar.DAY_OF_MONTH);// ? }