In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of "how to achieve android voice input". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Voice input is integrated with iFLYTEK's SDK, which simply realizes the process of converting speech into text. Of course, iFLYTEK also provides a lot of interfaces to achieve a more complex speech recognition system.
Layout file:
MainActivity comments are very detailed, do not repeat, do not understand can leave a message to learn together.
Package com.test.demo;import java.util.ArrayList;import android.app.Activity;import android.os.Bundle;import android.util.Log;import android.view.View;import android.view.View.OnClickListener;import android.widget.EditText;import com.iflytek.speech.RecognizerResult;import com.iflytek.speech.SpeechConfig.RATE;import com.iflytek.speech.SpeechError;import com.iflytek.ui.RecognizerDialog;import com.iflytek.ui.RecognizerDialogListener; public class HelloDemoActivity extends Activity implements OnClickListener {protected static final String TAG = "ThirdActivity"; private EditText txt_result Private RecognizerDialog rd; @ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.demo); findView (); / / RecognizerDialog (Context context, String params); "appid=1234567,usr=test,pwd=12345" usr, pwd are not required / / create speech recognition dailog objects. If appid goes to iFLYTEK, register to get rd = new RecognizerDialog (this, "appid= enter the ID you applied here") } private void findView () {txt_result = (EditText) findViewById (R.id.txt_result); findViewById (R.id.bt_search) .setOnClickListener (this);} @ Override public void onClick (View v) {switch (v.getId ()) {case R.id.bt_search: showReconigizerDialog (); break; default: break;}} private void showReconigizerDialog () {/ / setEngine (String engine,String params,String grammar) / * recognition engine selection, currently supports the following five "sms": plain text transfer "poi": place name search "vsearch": hot word search "vsearch": hot word search "video": video music search "asr": command word recognition params engine parameter configuration list additional parameter list, separated by a comma in the middle of each item For example, you can specify the search area when searching the map: "area= Hefei City, Anhui Province". No additional parameters can be passed to null * / rd.setEngine ("sms", null, null). / / set the sampling frequency. By default, Android phones only support 8k and 16k by default. For better identification, just make it 16k. Rd.setSampleRate (RATE.rate16k); final StringBuilder sb = new StringBuilder (); Log.i (TAG, "recognition ready to start."); / / set the callback result rd.setListener (new RecognizerDialogListener () {@ Override public void onResults (ArrayList result, boolean isLast) {for (RecognizerResult recognizerResult: result) {sb.append (recognizerResult.text)) Log.i (TAG, "identify a result is:" + recognizerResult.text);}} @ Override public void onEnd (SpeechError error) {Log.i (TAG, "recognition complete."); txt_result.setText (sb.toString ()); Log.i (TAG, "recognition complete:" + txt_result.getText (). ToString ());}}) Txt_result.setText (""); / / set it to empty first, and then set the content rd.show () after the recognition is completed.}} "how to implement android voice input" is introduced here. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.