Android手机语音控制家电的实现


ࠊ㋏㒳䞠䴶ˈ✊ৢЁ༂᥻ࠊ㋏㒳ᕫࠄⳌᑨⱘ݇䬂ᄫৢˈ㾺থⳌᑨⱘҷⷕˈএ᥻ࠊⳌᑨⱘ䆒໛DŽ ᠟ᴎˈ䇗⫼ GOOGLE ⱘ䇁㿔䆚߿ᓩ᪢ˈ᠟ᴎ䆚߿ࠄⳌᑨⱘ݇䬂ᄫৢˈ䗮䖛 HTTP থ䗕ࠄ WOOCU Ё༂᥻ ᅲ⦄⌕⿟ᅲ⦄⌕⿟ᅲ⦄⌕⿟ᅲ⦄⌕⿟˖ ˖˖˖ 㔥キϞ㛑ᡒࠄᓔ⑤ⱘ㓪⿟᠟ݠ.( Ң໪㾖ⳟ䞛⫼ 1U ⱘᴎㆅˈ䆹ѻકᑨ䆹ᰃ⫼ѢଚϮ⫼䗨ˈᬒᆊ䞠᳝⚍໻ˈ੉ ) ⹀ӊ㽕∖˖WIFI/ WAN/LAN/ ˈᬃᣕ㓪⿟,ᬃᣕ WEB API ᥹ষDŽ԰㗙ᡒࠄ WOOCU ⱘ WA4 DŽҢ݊ᅬᮍ ㄀Ѡ㄀Ѡ㄀Ѡ㄀Ѡ˖˖˖˖Ё༂᥻ࠊ㋏㒳Ё༂᥻ࠊ㋏㒳Ё༂᥻ࠊ㋏㒳Ё༂᥻ࠊ㋏㒳, ᅲ偠DŽخ⹀ӊ㽕∖˖ᬃᣕ Android V1.6 ⠜ᴀҹϞDŽ ԰㗙᠟Ϟ⫼ G1 ᴹ ㄀ϔ㄀ϔ㄀ϔ㄀ϔ˖˖˖˖ ᠟ᴎ᠟ᴎ᠟ᴎ᠟ᴎ ҢϞ೒ৃҹⳟߎˈ㽕ᅲ⦄⫼䇁䷇᥻ࠊᆊ⬉ˈᖙ乏乱໪໮ࡴ 2 Ͼ⹀ӊ䆒໛˖ ⳟⳟᭈϾ㋏㒳೒˖ܜϟ䴶 3. Woocu 㛮ᴀ㓪⿟˄৿ҷⷕ˅ 2. ໮ၦԧЁ᥻᥻ࠊ㋏㒳˄⹀ӊ䖲᥹˅ 1. Android Java 㓪⿟˄৿ҷⷕ˅ ݊Ёࣙᣀ˖ ᴀ᭛,ᦤկϔ⾡ৃ㸠ⱘ䇁䷇᥻ࠊ⬉఼ѻકⱘᮍḜ.᭛Ё⍝ঞࠄ䕃ӊ㓪⿟ҹঞ⹀ӊ䖲᥹ . (৿⑤ҷⷕ৿⑤ҷⷕ৿⑤ҷⷕ৿⑤ҷⷕ) Android+WOOCU 䇁䷇᥻ࠊᆊ⬉ⱘᅲ⦄䇁䷇᥻ࠊᆊ⬉ⱘᅲ⦄䇁䷇᥻ࠊᆊ⬉ⱘᅲ⦄䇁䷇᥻ࠊᆊ⬉ⱘᅲ⦄ { ;( " speakButton.setText( "Recognizer not present speakButton.setEnabled( false ); } else { speakButton.setOnClickListener( this ); if (activities.size() != 0) { new Intent(RecognizerIntent. ACTION_WEB_SEARCH), 0); 0); // new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), List activities = pm.queryIntentActivities( PackageManager pm = getPackageManager(); mList = (ListView) findViewById(R.id. list ); tv_rp = (TextView) this .findViewById(R.id. TextView ); // ߯ᓎ᭛ᴀḚ/ᰒ⼎HTTP ݙᆍ Button speakButton = (Button) findViewById(R.id. btn_speak ); // ߯ᓎᣝ䪂 setContentView(R.layout. main ); super .onCreate(savedInstanceState); public void onCreate(Bundle savedInstanceState) { @Override private TextView tv_rp = null ; private ListView mList ; private static final int VOICE_RECOGNITION_REQUEST_CODE = 1234; { public class MyStt1Activity extends Activity implements OnClickListener Android 䚼ߚⱘҷⷕབϟ˖ ৥Ё᥻ᦤѸ HTTP GET ⱘ⬇䇋DŽ ϟ䴶ᓔྟᅠ៤ Android 䚼ߚⱘ㓪⿟ˈ ⱘህᰃ৥ Ё᥻ᦤѸϔϾ http Get ⱘ⬇䇋DŽ⊼˖Ё᥻䆒໛Ꮖᏺ Http Server.خ݊Ёˈ Android ⿟ᑣ㽕 ᅠᭈ㔥キ˖ http://192.168.20.1/ control_voice.aspx? action=1&voice=[䇁䷇݇䬂ᄫ] খ᭄ 1 voice=[䇁䷇݇䬂ᄫ] ᦤѸᮍ⊩ GET / POST 䗮䆃ण䆂˖ HTTP ໻ὖᦣ䗄ϔϟ WOOCU ⱘ API ᥹ষᡔᴃ˖ܜ䖭䞠 } public void onClick(View v) { if (v.getId() == R.id. btn_speak ) { startMysttActivityActivity(); // ᓔྟ䇁䷇䆚߿ } } public void HttpGet(String httpUrl) { // TODO Auto-generated method stub //String httpUrl = "http://192.168.0.132:8080/Android/httpreq.jsp?par=request-get"; HttpGet request = new HttpGet(httpUrl); HttpClient httpClient = new DefaultHttpClient(); try { //httpClient.getParams().setParameter(httpClient.HTTP_CONTENT_CHA RSET, "gb2312"); HttpResponse response = httpClient.execute(request); if (response.getStatusLine().getStatusCode()==HttpStatus. SC_OK){ String str = EntityUtils. toString (response.getEntity()).trim(); tv_rp .setText( "䖨ಲᣛҸ˖"+str); } else { tv_rp .setText( "㔥㒰䇋∖༅䋹!"); } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } ; public Handler handler = new Handler(){ public void handleMessage(Message msg){ super .handleMessage(msg); } }; private void startMysttActivityActivity() { Intent intent = new Intent(RecognizerIntent. ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent. EXTRA_LANGUAGE_MODEL, RecognizerIntent. LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent. EXTRA_PROMPT, "䇋Փ⫼᱂䗮䆱៪㣅᭛ 䖯㸠᥻ࠊ"); startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE); } @Override protected void onActivityResult( int requestCode, int resultCode, Intent data) { if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) { try { String str=URLEncoder. encode (data.getStringArrayListExtra(RecognizerIntent. E XTRA_RESULTS).toString(), "GB2312" ); HttpGet( "http://192.168.20.248/woocu/control_voice.aspx?action=1& voice=" + str ); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } // Fill the list view with the strings the recognizer thought it could have heard ArrayList matches = data.getStringArrayListExtra( RecognizerIntent. EXTRA_RESULTS); mList .setAdapter( new ArrayAdapter( this , android.R.layout. simple_list_item_1 , matches)); } super .onActivityResult(requestCode, resultCode, data); } .IR.key1.send // ᡞ㑶໪ⷕথߎএᡞ㑶໪ⷕথߎএᡞ㑶໪ⷕথߎএᡞ㑶໪ⷕথߎএˈ ˈˈˈ䘹᥻⬉㾚䘹᥻⬉㾚䘹᥻⬉㾚䘹᥻⬉㾚 䯁݇ܝ♃䯁ᡞ݇ܝ♃䯁ᡞ݇ܝ♃䯁ᡞ݇ܝ♃Replay2.off // ᡞ Sleep 1 // ㄝᕙㄝᕙㄝᕙㄝᕙ 1 ⾦ৢ⾦ৢ⾦ৢ⾦ৢ Replay1.on // ᡞ⬉㾚ⱘ⬉⑤ᠧᓔᡞ⬉㾚ⱘ⬉⑤ᠧᓔᡞ⬉㾚ⱘ⬉⑤ᠧᓔᡞ⬉㾚ⱘ⬉⑤ᠧᓔ ᑊᠧᓔ⬉㾚ᑊᠧᓔ⬉㾚ᑊᠧᓔ⬉㾚ᑊᠧᓔ⬉㾚ˈ ˈˈˈ䇗㟇Ё༂ϔৄ䇗㟇Ё༂ϔৄ䇗㟇Ё༂ϔৄ䇗㟇Ё༂ϔৄ˖ ˖˖˖ˈˈˈ ˈܝ♃䯁݇ܝ♃䯁݇ܝ♃䯁݇ܝ♃// ݇䯁 Ё᥻䚼ߚⱘҷⷕབϟ˖ 5. 㑶໪ Key1 Ꮖ㒣ᄺд䖯এ,䘹᥻ࠄЁ༂ϔ༫. 4. Ё᥻ⱘ㑶໪থ䗕ẦᏆ㒣ᬒ㕂೼⬉㾚ᴎ䰘䖥. ᥹೼⬉⑤ⱘ᥻ࠊষ 2.ܝ♃ ,3. ⬉㾚ⱘ⬉⑤᥹ষ᥹೼Ё᥻ⱘ⬉⑤ষ 1 2. ᠟ᴎ᥹ܹЁ᥻᮴㒓㔥㒰ˈЁ᥻ WAN ষᏆ㒣㘨㔥. 䆒 Android ⱘ⿟ᑣᙼᏆ㒣㓪䆥䗮䖛ˈᑊৃҹℷ⹂䆚߿ .؛ .1 ᑊᑊᑊᑊᠧᓔᠧᓔᠧᓔᠧᓔ⬉㾚⬉㾚⬉㾚⬉㾚ˈˈˈˈ䇗㟇䇗㟇䇗㟇䇗㟇Ё༂ϔЁ༂ϔЁ༂ϔЁ༂ϔৄ ৄৄৄ˖˖˖˖ˈˈˈ ˈܝ♃䯁݇ܝ♃䯁݇ܝ♃䯁݇ܝ♃ϟ䴶ㅔऩᅲ⦄ϔϟ⫼䇁䷇᥻ࠊϟ䴶ㅔऩᅲ⦄ϔϟ⫼䇁䷇᥻ࠊϟ䴶ㅔऩᅲ⦄ϔϟ⫼䇁䷇᥻ࠊϟ䴶ㅔऩᅲ⦄ϔϟ⫼䇁䷇᥻ࠊˈ ˈˈˈ݇䯁 Sleep 1 // ᓊᯊ໮ᇥ⾦ 5. ㋏㒳ᣛҸ Http.Get URL 㓪⿟ҷⷕ˖ ৃҹᅲ⦄ ৥߿ⱘ䆒໛ᦤѸ HTTP 䇋∖ˈ⫼Ѣ᥻ࠊ⬉㛥ㄝሙѢ HTTP ण䆂ⱘ䆒໛DŽ 4. Http ᥹ষ Replay2.Off // ⬉⑤݇ Replay1.On // ⬉⑤ᓔ 㓪⿟ҷⷕ˖ 3. 㞾ᏺ 220V ⬉⑤᥻ࠊ⬉⑤᥻ࠊ⬉⑤᥻ࠊ⬉⑤᥻ࠊষ ,݅ 2 Ͼ. Com1.SendHex —0A 0B 01 0D“ // ৥䆒໛থ䗕 16 䖯ࠊҷⷕ Com1.set —9600,8,N,1“ 㓪⿟ҷⷕབϟ˖ 2. RS232 ІষІষІষІষ,݅ 8 Ͼ,ৃҹ᥻ࠊ᠔᳝ RS232 ⱘ䆒໛ˈ՟བᡩᕅᴎ ,⬉ࡼにᏬ,⬉⑤᥻ࠊ఼ㄝDŽ IR.Key1.Send // থ䗕㄀ϔϾ䬂 ˈ݅ 255 Ͼ IR.Key1.Learn // ᄺд㄀ϔϾ䬂 ˈ݅ 255 Ͼ 㓪⿟ҷⷕ˖ 1. 㑶໪᥻ࠊ㑶໪᥻ࠊ㑶໪᥻ࠊ㑶໪᥻ࠊˈ䆹Ё᥻㞾ᏺ 2 Ͼ㑶໪ᄺд᥻ࠊষˈৃҹᄺдᑊ᥻ࠊ᠔᳝㑶໪䆒໛ .⬉㾚ˈ DVD ㄝDŽ ϟ䴶ϟ䴶ϟ䴶ϟ䴶ㅔऩㅔऩㅔऩㅔऩ䆆㾷ϔϟЁ᥻བԩ᥻ࠊᆊ⫼⬉఼䆆㾷ϔϟЁ᥻བԩ᥻ࠊᆊ⫼⬉఼䆆㾷ϔϟЁ᥻བԩ᥻ࠊᆊ⫼⬉఼䆆㾷ϔϟЁ᥻བԩ᥻ࠊᆊ⫼⬉఼ˈ ˈˈˈҹঞབԩ㓪⿟ⱘҹঞབԩ㓪⿟ⱘҹঞབԩ㓪⿟ⱘҹঞབԩ㓪⿟ⱘ. { 2010.12.5 KLAU Woocu 㓪⿟ܹ䮼᠟ݠ˖ http://www.woocu.com/ Android 䇁㿔䆚߿᠟ݠ: http://www.android.com ᕜ໮ᱎ㛑࣪ⱘϰ㽓ˈ಴Ўᅗᰃৃҹ㓪⿟ⱘˈ੉੉DŽᛳ݈䍷ⱘৃҹ㞾ᏅϞ㔥এᶹ䌘᭭˖خ㛑 ᱖ᯊݭ䖭М໮ˈৢ䴶⹀ӊⱘ䚼ߚϡᰃ៥ⱘ⡍䭓ˈ᮴⊩ϔϔὖ䗄ˈ݋ԧᑨ⫼ৃҹ㞾Ꮕᴹᠽሩˈ ៾೒བϟ៾೒བϟ៾೒བϟ៾೒བϟ˖ ˖˖˖ ⥛ⱘ䯂乬ˈ໮฿ѯ݇䬂ᄫϞএህ៤њDŽ੉੉DŽ ҹ㾺থ䖭↉ҷⷕˈᓔ⬉㾚ˈᑊ䇗ࠄЁ༂ϔ༫ˈ੉੉DŽህᰃ䖭Ͼϰϰˈৃҹ䅽Դϡ⫼㗗㰥䆚߿ гৃˈޚ䖭ᰃ⬅Ѣ៥᱂䗮䆱ϡདˈ㗕䆚߿៤ ϰ༂ϔ༫,៥ᑆ㛚฿Ϟএˈ䖭ḋϛϔ៥থ䷇ϡᷛ Voice Control ໘៥฿њ໘៥฿њ໘៥฿њ໘៥฿њ˖ ˖˖˖[Ё༂ϔৄЁ༂ϔৄЁ༂ϔৄЁ༂ϔৄ] [ Ё༂ϔ༫Ё༂ϔ༫Ё༂ϔ༫Ё༂ϔ༫][ ϰ༂ϔ༫ϰ༂ϔ༫ϰ༂ϔ༫ϰ༂ϔ༫] 㛑ৃҹᅲ⦄ᮍ㿔ⱘ䆚߿㛑ৃҹᅲ⦄ᮍ㿔ⱘ䆚߿㛑ৃҹᅲ⦄ᮍ㿔ⱘ䆚߿㛑ৃҹᅲ⦄ᮍ㿔ⱘ䆚߿ˈ ˈˈˈгϡ⫼㗗㰥䆚߿⥛ⱘ䯂乬гϡ⫼㗗㰥䆚߿⥛ⱘ䯂乬гϡ⫼㗗㰥䆚߿⥛ⱘ䯂乬гϡ⫼㗗㰥䆚߿⥛ⱘ䯂乬DŽ DŽDŽDŽ гህᰃ䇈гህᰃ䇈гህᰃ䇈гህᰃ䇈ˈ ˈˈˈAndroid 䙷䖍䆚߿њҔМᄫߎᴹ䙷䖍䆚߿њҔМᄫߎᴹ䙷䖍䆚߿њҔМᄫߎᴹ䙷䖍䆚߿њҔМᄫߎᴹˈ ˈˈˈԴԴԴԴᏠᳯ㾺থϞ䴶ⱘҷⷕᏠᳯ㾺থϞ䴶ⱘҷⷕᏠᳯ㾺থϞ䴶ⱘҷⷕᏠᳯ㾺থϞ䴶ⱘҷⷕˈ ˈˈˈህ฿䖯এህ฿䖯এህ฿䖯এህ฿䖯এDŽ DŽDŽDŽ䖭Ͼࡳ䖭Ͼࡳ䖭Ͼࡳ䖭Ͼࡳ ϟ䴶ᰃϟ䴶ᰃϟ䴶ᰃϟ䴶ᰃϔϾ䞡⚍ϔϾ䞡⚍ϔϾ䞡⚍ϔϾ䞡⚍ˈ ˈˈˈህᰃ㽕೼ህᰃ㽕೼ህᰃ㽕೼ህᰃ㽕೼Ё᥻ⱘЁ᥻ⱘЁ᥻ⱘЁ᥻ⱘ㓪⿟⬠䴶㓪⿟⬠䴶㓪⿟⬠䴶㓪⿟⬠䴶Ϟ ϞϞϞˈˈˈˈ᳝᳝᳝᳝ϔϾϔϾϔϾϔϾ Voice Control ໘฿Ϟ݇䬂ᄫ໘฿Ϟ݇䬂ᄫ໘฿Ϟ݇䬂ᄫ໘฿Ϟ݇䬂ᄫˈ ˈˈˈ
还剩5页未读

继续阅读

下载pdf到电脑,查找使用更方便

pdf的实际排版效果,会与网站的显示效果略有不同!!

需要 5 金币 [ 分享pdf获得金币 ] 3 人已下载

下载pdf

pdf贡献者

q403707995

贡献于2013-05-23

下载需要 5 金币 [金币充值 ]
亲,您也可以通过 分享原创pdf 来获得金币奖励!
下载pdf