Skip to content

Commit

Permalink
init project
Browse files Browse the repository at this point in the history
  • Loading branch information
jicheng.gujc committed Oct 17, 2013
0 parents commit bbc6433
Show file tree
Hide file tree
Showing 27 changed files with 1,843 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bin/*
gen/*

39 changes: 39 additions & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sinvoicedemo"
android:versionCode="1"
android:versionName="1.0" >

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"></uses-permission>

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="10" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:configChanges="orientation|keyboard"
android:name="com.example.sinvoicedemo.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<service android:name=".MyService">
<intent-filter>
<action android:name="com.my.IService"></action>
</intent-filter>
</service>

</application>

</manifest>
Binary file added ic_launcher-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added libs/android-support-v4.jar
Binary file not shown.
3 changes: 3 additions & 0 deletions lint.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<lint>
</lint>
20 changes: 20 additions & 0 deletions proguard-project.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
14 changes: 14 additions & 0 deletions project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-17
Binary file added res/drawable-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-hdpi/ic_lock_alarm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-ldpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 56 additions & 0 deletions res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/start_reg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="start reg" />

<Button
android:id="@+id/stop_reg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="stop reg" />
<TextView
android:id="@+id/regtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="recognised text" />
</LinearLayout>

<LinearLayout
android:layout_marginLeft="20dp"
android:layout_marginTop="50dp"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<Button
android:id="@+id/start_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="start play" />

<Button
android:id="@+id/stop_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="stop play" />
<TextView
android:id="@+id/playtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="play text" />

</LinearLayout>

</LinearLayout>
8 changes: 8 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name">SinVoiceDemo</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>

</resources>
20 changes: 20 additions & 0 deletions res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<resources>

<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

</resources>
149 changes: 149 additions & 0 deletions src/com/example/sinvoicedemo/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
package com.example.sinvoicedemo;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.libra.sinvoice.LogHelper;
import com.libra.sinvoice.SinVoicePlayer;
import com.libra.sinvoice.SinVoiceRecognition;

public class MainActivity extends Activity implements SinVoiceRecognition.Listener, SinVoicePlayer.Listener {
private final static String TAG = "MainActivity";
private final static int MAX_NUMBER = 5;
private final static int MSG_SET_RECG_TEXT = 1;
private final static int MSG_RECG_START = 2;
private final static int MSG_RECG_END = 3;

private final static String CODEBOOK = "12345";

private Handler mHanlder;
private SinVoicePlayer mSinVoicePlayer;
private SinVoiceRecognition mRecognition;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mSinVoicePlayer = new SinVoicePlayer(CODEBOOK);
mSinVoicePlayer.setListener(this);

mRecognition = new SinVoiceRecognition(CODEBOOK);
mRecognition.setListener(this);

final TextView playTextView = (TextView) findViewById(R.id.playtext);
TextView recognisedTextView = (TextView) findViewById(R.id.regtext);
mHanlder = new RegHandler(recognisedTextView);

Button playStart = (Button) this.findViewById(R.id.start_play);
playStart.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
String text = genText(7);
playTextView.setText(text);
mSinVoicePlayer.play(text);
}
});

Button playStop = (Button) this.findViewById(R.id.stop_play);
playStop.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
mSinVoicePlayer.stop();
}
});

Button recognitionStart = (Button) this.findViewById(R.id.start_reg);
recognitionStart.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
mRecognition.start();
}
});

Button recognitionStop = (Button) this.findViewById(R.id.stop_reg);
recognitionStop.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
mRecognition.stop();
}
});
}

private String genText(int count) {
StringBuilder sb = new StringBuilder();
int pre = 0;
while (count > 0) {
int x = (int) (Math.random() * MAX_NUMBER + 1);
if (Math.abs(x - pre) > 0) {
sb.append(x);
--count;
pre = x;
}
}

return sb.toString();
}

private static class RegHandler extends Handler {
private StringBuilder mTextBuilder = new StringBuilder();
private TextView mRecognisedTextView;

public RegHandler(TextView textView) {
mRecognisedTextView = textView;
}

@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MSG_SET_RECG_TEXT:
char ch = (char) msg.arg1;
mTextBuilder.append(ch);
if (null != mRecognisedTextView) {
mRecognisedTextView.setText(mTextBuilder.toString());
}
break;

case MSG_RECG_START:
mTextBuilder.delete(0, mTextBuilder.length());
break;

case MSG_RECG_END:
LogHelper.d(TAG, "recognition end");
break;
}
super.handleMessage(msg);
}
}

@Override
public void onRecognitionStart() {
mHanlder.sendEmptyMessage(MSG_RECG_START);
}

@Override
public void onRecognition(char ch) {
mHanlder.sendMessage(mHanlder.obtainMessage(MSG_SET_RECG_TEXT, ch, 0));
}

@Override
public void onRecognitionEnd() {
mHanlder.sendEmptyMessage(MSG_RECG_END);
}

@Override
public void onPlayStart() {
LogHelper.d(TAG, "start play");
}

@Override
public void onPlayEnd() {
LogHelper.d(TAG, "stop play");
}

}
Loading

0 comments on commit bbc6433

Please sign in to comment.