| After Width: | Height: | Size: 1.4 KiB | 
| After Width: | Height: | Size: 14 KiB | 
| After Width: | Height: | Size: 16 KiB | 
| After Width: | Height: | Size: 12 KiB | 
| After Width: | Height: | Size: 7.7 KiB | 
| @ -0,0 +1,36 @@ | |||||||
|  | package com.example.myapplication; | ||||||
|  | 
 | ||||||
|  | import android.os.Bundle; | ||||||
|  | import android.preference.EditTextPreference; | ||||||
|  | import android.preference.Preference; | ||||||
|  | import android.preference.Preference.OnPreferenceChangeListener; | ||||||
|  | import android.preference.PreferenceActivity; | ||||||
|  | import android.view.Window; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * 听写设置界面 | ||||||
|  |  */ | ||||||
|  | public class IatSettings extends PreferenceActivity implements OnPreferenceChangeListener { | ||||||
|  | 
 | ||||||
|  |     public static final String PREFER_NAME = "com.inflater.setting"; | ||||||
|  | 
 | ||||||
|  |     @SuppressWarnings("deprecation") | ||||||
|  |     public void onCreate(Bundle savedInstanceState) { | ||||||
|  |         requestWindowFeature(Window.FEATURE_NO_TITLE); | ||||||
|  |         super.onCreate(savedInstanceState); | ||||||
|  |         getPreferenceManager().setSharedPreferencesName(PREFER_NAME); | ||||||
|  |         addPreferencesFromResource(R.xml.iat_setting); | ||||||
|  | 
 | ||||||
|  |         EditTextPreference mVadbosPreference = (EditTextPreference) findPreference("iat_vadbos_preference"); | ||||||
|  |         mVadbosPreference.getEditText().addTextChangedListener(new SettingTextWatcher(IatSettings.this, mVadbosPreference, 0, 10000)); | ||||||
|  | 
 | ||||||
|  |         EditTextPreference mVadeosPreference = (EditTextPreference) findPreference("iat_vadeos_preference"); | ||||||
|  |         mVadeosPreference.getEditText().addTextChangedListener(new SettingTextWatcher(IatSettings.this, mVadeosPreference, 0, 10000)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public boolean onPreferenceChange(Preference preference, Object newValue) { | ||||||
|  |         return true; | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -0,0 +1,117 @@ | |||||||
|  | package com.example.myapplication; | ||||||
|  | 
 | ||||||
|  | import org.json.JSONArray; | ||||||
|  | import org.json.JSONObject; | ||||||
|  | import org.json.JSONTokener; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Json结果解析类 | ||||||
|  |  */ | ||||||
|  | public class JsonParser { | ||||||
|  | 
 | ||||||
|  | 	public static String parseIatResult(String json) { | ||||||
|  | 		StringBuffer ret = new StringBuffer(); | ||||||
|  | 		try { | ||||||
|  | 			JSONTokener tokener = new JSONTokener(json); | ||||||
|  | 			JSONObject joResult = new JSONObject(tokener); | ||||||
|  | 
 | ||||||
|  | 			JSONArray words = joResult.getJSONArray("ws"); | ||||||
|  | 			for (int i = 0; i < words.length(); i++) { | ||||||
|  | 				// 转写结果词,默认使用第一个结果
 | ||||||
|  | 				JSONArray items = words.getJSONObject(i).getJSONArray("cw"); | ||||||
|  | 				JSONObject obj = items.getJSONObject(0); | ||||||
|  | 				ret.append(obj.getString("w")); | ||||||
|  | //				如果需要多候选结果,解析数组其他字段
 | ||||||
|  | //				for(int j = 0; j < items.length(); j++)
 | ||||||
|  | //				{
 | ||||||
|  | //					JSONObject obj = items.getJSONObject(j);
 | ||||||
|  | //					ret.append(obj.getString("w"));
 | ||||||
|  | //				}
 | ||||||
|  | 			} | ||||||
|  | 		} catch (Exception e) { | ||||||
|  | 			e.printStackTrace(); | ||||||
|  | 		}  | ||||||
|  | 		return ret.toString(); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	public static String parseGrammarResult(String json) { | ||||||
|  | 		StringBuffer ret = new StringBuffer(); | ||||||
|  | 		try { | ||||||
|  | 			JSONTokener tokener = new JSONTokener(json); | ||||||
|  | 			JSONObject joResult = new JSONObject(tokener); | ||||||
|  | 
 | ||||||
|  | 			JSONArray words = joResult.getJSONArray("ws"); | ||||||
|  | 			for (int i = 0; i < words.length(); i++) { | ||||||
|  | 				JSONArray items = words.getJSONObject(i).getJSONArray("cw"); | ||||||
|  | 				for(int j = 0; j < items.length(); j++) | ||||||
|  | 				{ | ||||||
|  | 					JSONObject obj = items.getJSONObject(j); | ||||||
|  | 					if(obj.getString("w").contains("nomatch")) | ||||||
|  | 					{ | ||||||
|  | 						ret.append("没有匹配结果."); | ||||||
|  | 						return ret.toString(); | ||||||
|  | 					} | ||||||
|  | 					ret.append("【结果】" + obj.getString("w")); | ||||||
|  | 					ret.append("【置信度】" + obj.getInt("sc")); | ||||||
|  | 					ret.append("\n"); | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 		} catch (Exception e) { | ||||||
|  | 			e.printStackTrace(); | ||||||
|  | 			ret.append("没有匹配结果."); | ||||||
|  | 		}  | ||||||
|  | 		return ret.toString(); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	public static String parseLocalGrammarResult(String json) { | ||||||
|  | 		StringBuffer ret = new StringBuffer(); | ||||||
|  | 		try { | ||||||
|  | 			JSONTokener tokener = new JSONTokener(json); | ||||||
|  | 			JSONObject joResult = new JSONObject(tokener); | ||||||
|  | 
 | ||||||
|  | 			JSONArray words = joResult.getJSONArray("ws"); | ||||||
|  | 			for (int i = 0; i < words.length(); i++) { | ||||||
|  | 				JSONArray items = words.getJSONObject(i).getJSONArray("cw"); | ||||||
|  | 				for(int j = 0; j < items.length(); j++) | ||||||
|  | 				{ | ||||||
|  | 					JSONObject obj = items.getJSONObject(j); | ||||||
|  | 					if(obj.getString("w").contains("nomatch")) | ||||||
|  | 					{ | ||||||
|  | 						ret.append("没有匹配结果."); | ||||||
|  | 						return ret.toString(); | ||||||
|  | 					} | ||||||
|  | 					ret.append("【结果】" + obj.getString("w")); | ||||||
|  | 					ret.append("\n"); | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 			ret.append("【置信度】" + joResult.optInt("sc")); | ||||||
|  | 
 | ||||||
|  | 		} catch (Exception e) { | ||||||
|  | 			e.printStackTrace(); | ||||||
|  | 			ret.append("没有匹配结果."); | ||||||
|  | 		}  | ||||||
|  | 		return ret.toString(); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	public static String parseTransResult(String json,String key) { | ||||||
|  | 		StringBuffer ret = new StringBuffer(); | ||||||
|  | 		try { | ||||||
|  | 			JSONTokener tokener = new JSONTokener(json); | ||||||
|  | 			JSONObject joResult = new JSONObject(tokener); | ||||||
|  | 			String errorCode = joResult.optString("ret"); | ||||||
|  | 			if(!errorCode.equals("0")) { | ||||||
|  | 				return joResult.optString("errmsg"); | ||||||
|  | 			} | ||||||
|  | 			JSONObject transResult = joResult.optJSONObject("trans_result"); | ||||||
|  | 			ret.append(transResult.optString(key)); | ||||||
|  | 			/*JSONArray words = joResult.getJSONArray("results"); | ||||||
|  | 			for (int i = 0; i < words.length(); i++) { | ||||||
|  | 				JSONObject obj = words.getJSONObject(i); | ||||||
|  | 				ret.append(obj.getString(key)); | ||||||
|  | 			}*/ | ||||||
|  | 		} catch (Exception e) { | ||||||
|  | 			e.printStackTrace(); | ||||||
|  | 		} | ||||||
|  | 		return ret.toString(); | ||||||
|  | 	} | ||||||
|  | } | ||||||
| @ -0,0 +1,71 @@ | |||||||
|  | package com.example.myapplication; | ||||||
|  | 
 | ||||||
|  | import android.content.Context; | ||||||
|  | import android.preference.EditTextPreference; | ||||||
|  | import android.text.Editable; | ||||||
|  | import android.text.TextUtils; | ||||||
|  | import android.text.TextWatcher; | ||||||
|  | import android.widget.Toast; | ||||||
|  | 
 | ||||||
|  | import java.util.regex.Pattern; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * 输入框输入范围控制 | ||||||
|  |  */ | ||||||
|  | public class SettingTextWatcher implements TextWatcher { | ||||||
|  |     private int editStart; | ||||||
|  |     private int editCount; | ||||||
|  |     private EditTextPreference mEditTextPreference; | ||||||
|  |     int minValue;//最小值
 | ||||||
|  |     int maxValue;//最大值
 | ||||||
|  |     private Context mContext; | ||||||
|  | 
 | ||||||
|  |     public SettingTextWatcher(Context context, EditTextPreference e, int min, int max) { | ||||||
|  |         mContext = context; | ||||||
|  |         mEditTextPreference = e; | ||||||
|  |         minValue = min; | ||||||
|  |         maxValue = max; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void onTextChanged(CharSequence s, int start, int before, int count) { | ||||||
|  | //		Log.e("demo", "onTextChanged start:"+start+" count:"+count+" before:"+before);
 | ||||||
|  |         editStart = start; | ||||||
|  |         editCount = count; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void beforeTextChanged(CharSequence s, int start, int count, int after) { | ||||||
|  | //		Log.e("demo", "beforeTextChanged start:"+start+" count:"+count+" after:"+after);
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void afterTextChanged(Editable s) { | ||||||
|  |         if (TextUtils.isEmpty(s)) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |         String content = s.toString(); | ||||||
|  | //		Log.e("demo", "content:"+content);
 | ||||||
|  |         if (isNumeric(content)) { | ||||||
|  |             int num = Integer.parseInt(content); | ||||||
|  |             if (num > maxValue || num < minValue) { | ||||||
|  |                 s.delete(editStart, editStart + editCount); | ||||||
|  |                 mEditTextPreference.getEditText().setText(s); | ||||||
|  |                 Toast.makeText(mContext, "超出有效值范围", Toast.LENGTH_SHORT).show(); | ||||||
|  |             } | ||||||
|  |         } else { | ||||||
|  |             s.delete(editStart, editStart + editCount); | ||||||
|  |             mEditTextPreference.getEditText().setText(s); | ||||||
|  |             Toast.makeText(mContext, "只能输入数字哦", Toast.LENGTH_SHORT).show(); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 正则表达式-判断是否为数字 | ||||||
|  |      */ | ||||||
|  |     public static boolean isNumeric(String str) { | ||||||
|  |         Pattern pattern = Pattern.compile("[0-9]*"); | ||||||
|  |         return pattern.matcher(str).matches(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | }; | ||||||
| @ -0,0 +1,18 @@ | |||||||
|  | package com.example.myapplication; | ||||||
|  | 
 | ||||||
|  | import android.app.Application; | ||||||
|  | 
 | ||||||
|  | import com.iflytek.cloud.SpeechUtility; | ||||||
|  | 
 | ||||||
|  | public class SpeechApplication extends Application { | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void onCreate() { | ||||||
|  | 
 | ||||||
|  |         //   5ef048e1  为在开放平台注册的APPID  注意没有空格,直接替换即可
 | ||||||
|  |         SpeechUtility.createUtility(SpeechApplication.this, "appid=6d0c39e4"); | ||||||
|  | 
 | ||||||
|  |         super.onCreate(); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| After Width: | Height: | Size: 4.5 KiB | 
| After Width: | Height: | Size: 3.8 KiB | 
| After Width: | Height: | Size: 2.3 KiB | 
| After Width: | Height: | Size: 3.3 KiB | 
| @ -0,0 +1,9 @@ | |||||||
|  | <?xml version="1.0" encoding="utf-8"?> | ||||||
|  | <selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||||||
|  | 
 | ||||||
|  |     <item android:drawable="@drawable/setting" android:state_focused="true" android:state_pressed="false" /> | ||||||
|  |     <item android:drawable="@drawable/setting_p" android:state_focused="true" android:state_pressed="true" /> | ||||||
|  |     <item android:drawable="@drawable/setting_p" android:state_focused="false" android:state_pressed="true" /> | ||||||
|  |     <item android:drawable="@drawable/setting"></item> | ||||||
|  | 
 | ||||||
|  | </selector> | ||||||
| After Width: | Height: | Size: 4.4 KiB | 
| After Width: | Height: | Size: 2.1 KiB | 
| After Width: | Height: | Size: 1.7 KiB | 
| @ -0,0 +1,13 @@ | |||||||
|  | <?xml version="1.0" encoding="utf-8"?> | ||||||
|  | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||||||
|  |     xmlns:tools="http://schemas.android.com/tools" | ||||||
|  |     android:layout_width="match_parent" | ||||||
|  |     android:layout_height="match_parent" | ||||||
|  |     tools:context=".class1"> | ||||||
|  | 
 | ||||||
|  |     <ListView | ||||||
|  |         android:id="@+id/lv_main_list" | ||||||
|  |         android:layout_width="match_parent" | ||||||
|  |         android:layout_height="match_parent"></ListView> | ||||||
|  | 
 | ||||||
|  | </LinearLayout> | ||||||
| @ -1,25 +1,25 @@ | |||||||
| <?xml version="1.0" encoding="utf-8"?> | <?xml version="1.0" encoding="utf-8"?> | ||||||
| <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||||||
|  |     xmlns:app="http://schemas.android.com/apk/res-auto" | ||||||
|  |     xmlns:tools="http://schemas.android.com/tools" | ||||||
|     android:layout_width="match_parent" |     android:layout_width="match_parent" | ||||||
|     android:layout_height="match_parent" |     android:layout_height="match_parent" | ||||||
|     android:orientation="vertical"> |     android:gravity="center" | ||||||
|  |     android:orientation="vertical" | ||||||
|  |     tools:context=".yuyin"> | ||||||
| 
 | 
 | ||||||
|     <Button |     <TextView | ||||||
|  |         android:id="@+id/tv_result" | ||||||
|         android:layout_width="wrap_content" |         android:layout_width="wrap_content" | ||||||
|         android:layout_height="70dp" |         android:layout_height="wrap_content" | ||||||
|         android:text="开始语音识别" |         android:text="识别到的内容" | ||||||
|         android:textSize="30sp" |         android:textColor="#000" /> | ||||||
|         android:gravity="left"></Button> | 
 | ||||||
|     <Button |     <Button | ||||||
|  |         android:id="@+id/btn_start" | ||||||
|         android:layout_width="wrap_content" |         android:layout_width="wrap_content" | ||||||
|         android:layout_height="70dp" |         android:layout_height="wrap_content" | ||||||
|         android:text="查看语音识别结果" |         android:layout_marginTop="20dp" | ||||||
|         android:textSize="30sp" |         android:text="开始识别" /> | ||||||
|         android:gravity="left"></Button> |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| </LinearLayout> | </LinearLayout> | ||||||
|  | 
 | ||||||
|  | |||||||
| @ -0,0 +1,14 @@ | |||||||
|  | <?xml version="1.0" encoding="utf-8"?> | ||||||
|  | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||||||
|  |     xmlns:app="http://schemas.android.com/apk/res-auto" | ||||||
|  |     xmlns:tools="http://schemas.android.com/tools" | ||||||
|  |     android:layout_width="match_parent" | ||||||
|  |     android:layout_height="match_parent" | ||||||
|  |     tools:context=".MainActivity"> | ||||||
|  | 
 | ||||||
|  |     <ListView | ||||||
|  |         android:id="@+id/lv_main_list" | ||||||
|  |         android:layout_width="match_parent" | ||||||
|  |         android:layout_height="match_parent"></ListView> | ||||||
|  | 
 | ||||||
|  | </LinearLayout> | ||||||
| @ -0,0 +1,9 @@ | |||||||
|  | <?xml version="1.0" encoding="utf-8"?> | ||||||
|  | <resources> | ||||||
|  |     <string-array name="iat_language_value" /> | ||||||
|  |     <string-array name="iat_language_entries" /> | ||||||
|  |     <string-array name="language_values" /> | ||||||
|  |     <string-array name="language_entries" /> | ||||||
|  |     <string-array name="punc_entries" /> | ||||||
|  |     <string-array name="punc_values" /> | ||||||
|  | </resources> | ||||||
| @ -0,0 +1,11 @@ | |||||||
|  | <?xml version="1.0" encoding="utf-8"?> | ||||||
|  | 
 | ||||||
|  | <resources> | ||||||
|  |     <dimen name="margin_">10dp</dimen> | ||||||
|  |     <dimen name="pading_">5dp</dimen> | ||||||
|  |     <dimen name="btn_size">22sp</dimen> | ||||||
|  |     <dimen name="txt_size">18sp</dimen> | ||||||
|  | 
 | ||||||
|  |     <!-- 分割线高度 --> | ||||||
|  |     <dimen name="line_height">1dp</dimen> | ||||||
|  | </resources> | ||||||
| @ -0,0 +1,18 @@ | |||||||
|  | <?xml version="1.0" encoding="utf-8"?> | ||||||
|  | <resources> | ||||||
|  | 
 | ||||||
|  |     <style name="dialog" parent="@android:style/Theme.Dialog"> | ||||||
|  |         <item name="android:windowFrame">@null</item> | ||||||
|  |         <item name="android:windowIsFloating">true</item> | ||||||
|  |         <item name="android:windowIsTranslucent">true</item> | ||||||
|  |         <item name="android:windowNoTitle">true</item> | ||||||
|  |         <item name="android:background">@android:color/transparent</item> | ||||||
|  |         <item name="android:windowBackground">@android:color/transparent</item> | ||||||
|  |         <item name="android:backgroundDimEnabled">true</item> | ||||||
|  |         <item name="android:backgroundDimAmount">0.6</item> | ||||||
|  |     </style> | ||||||
|  | 
 | ||||||
|  |     <style name="textStyle"> | ||||||
|  |         <item name="android:textSize">16sp</item> | ||||||
|  |     </style> | ||||||
|  | </resources> | ||||||
| @ -0,0 +1,6 @@ | |||||||
|  | <?xml version="1.0" encoding="utf-8"?> | ||||||
|  | <paths xmlns:android="http://schemas.android.com/apk/res/android"> | ||||||
|  |     <external-path | ||||||
|  |         name="my_images" | ||||||
|  |         path="."/> | ||||||
|  | </paths> | ||||||