Skip to content

Commit

Permalink
Improved the app
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander James Wallar committed Jan 21, 2014
1 parent ae70b5d commit cce8084
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 69 deletions.
2 changes: 1 addition & 1 deletion app/Locabean/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="11"
android:minSdkVersion="14"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
Expand Down
69 changes: 50 additions & 19 deletions app/Locabean/res/layout/activity_node.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mainView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
Expand All @@ -9,39 +10,69 @@
tools:context=".NodeActivity" >

<TextView
android:id="@+id/fingerprintLabel"
android:id="@+id/nameLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="17dp"
android:text="@string/fingerprint"
android:layout_alignLeft="@+id/btnStart"
android:layout_alignParentTop="true"
android:layout_marginTop="79dp"
android:text="@string/name"
android:textAppearance="?android:attr/textAppearanceLarge" />

<Button
android:id="@+id/btnStop"
android:layout_width="match_parent"
<TextView
android:id="@+id/confidenceLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/fingerprintText"
android:layout_alignParentBottom="true"
android:layout_marginBottom="37dp"
android:text="@string/stop" />
android:layout_alignLeft="@+id/nameLabel"
android:layout_below="@+id/nameLabel"
android:layout_marginTop="20dp"
android:text="@string/confidence"
android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
android:id="@+id/nameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/nameLabel"
android:layout_alignBottom="@+id/nameLabel"
android:layout_marginLeft="65dp"
android:layout_toRightOf="@+id/confidenceLabel"
android:text="@string/nameItl" />

<TextView
android:id="@+id/confidenceTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/confidenceLabel"
android:layout_alignBottom="@+id/confidenceLabel"
android:layout_alignLeft="@+id/nameTextView"
android:text="@string/confidenceItl" />

<Button
android:id="@+id/btnStart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/btnStop"
android:layout_alignLeft="@+id/btnStop"
android:layout_marginBottom="23dp"
android:layout_marginBottom="15dp"
android:text="@string/record" />

<TextView
android:id="@+id/fingerprintText"
<Button
android:id="@+id/btnSend"
android:layout_width="match_parent"
android:layout_height="500dp"
android:layout_alignLeft="@+id/fingerprintLabel"
android:layout_below="@+id/fingerprintLabel"
android:layout_marginTop="36dp"
android:maxLines="100"
android:scrollbars="vertical" />
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btnStop"
android:layout_alignParentBottom="true"
android:layout_marginBottom="34dp"
android:text="@string/send" />

<Button
android:id="@+id/btnStop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/btnSend"
android:layout_centerHorizontal="true"
android:layout_marginBottom="17dp"
android:text="@string/stop" />

</RelativeLayout>
6 changes: 5 additions & 1 deletion app/Locabean/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
<string name="hello_world">Hello world!</string>
<string name="record">Record</string>
<string name="stop">Stop</string>
<string name="fingerprint"><b>Fingerprint:</b></string>
<string name="name"><b>Name:</b></string>
<string name="confidence"><b>Confidence:</b></string>
<string name="nameItl"><it>Sound Name</it></string>
<string name="confidenceItl"><it>Recognition Confidence</it></string>
<string name="send">Send</string>

</resources>
9 changes: 2 additions & 7 deletions app/Locabean/src/com/locaudio/api/Locaudio.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package com.locaudio.api;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;

import com.locaudio.net.*;

public class Locaudio extends Requests {
Expand All @@ -21,14 +17,13 @@ public SoundLocation[] getSoundLocations(final String soundName) {
return agr.getResponse(this);
}

public String[] getNames() throws ClientProtocolException, IOException {
public String[] getNames() {
AsyncGetRequest<String[]> agr = new AsyncGetRequest<String[]>(
String[].class, NAMES_ROUTE);
return agr.getResponse(this);
}

public NotifyResponse notifyEvent(final NotifyForm event)
throws ClientProtocolException, IOException {
public NotifyResponse notifyEvent(final NotifyForm event) {
AsyncPostRequest<NotifyResponse> apr = new AsyncPostRequest<NotifyResponse>(
NotifyResponse.class, event.toMap(), NOTIFY_ROUTE);

Expand Down
12 changes: 9 additions & 3 deletions app/Locabean/src/com/locaudio/api/NotifyResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
public class NotifyResponse {
@SerializedName("error")
public int error;

@SerializedName("message")
public String message;

@SerializedName("name")
public String name;

@SerializedName("confidence")
public float confidence;

@Override
public String toString() {
return "{ Error: " + this.error + ", Message: " + this.message
+ ", Name: " + this.name + ", Confidence: " + this.confidence + " }";
}
}
15 changes: 14 additions & 1 deletion app/Locabean/src/com/locaudio/io/WaveWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public class WaveWriter {
private static final String AUDIO_RECORDER_FOLDER = "LocabeanAudio";
private static final String AUDIO_RECORDER_TEMP_FILE = "record_temp.raw";
private static final String AUDIO_RECORDER_FILENAME = "locabean_audio";

private static final String AUDIO_RECORDER_THREAD_NAME = "LocabeanRecorderThread";
public static final int AUDIO_RECORDER_ON_STATE = 1;

@SuppressWarnings("deprecation")
protected static final int RECORDER_CHANNELS = AudioFormat.CHANNEL_CONFIGURATION_MONO;
protected static final int RECORDER_BPP = 16;
Expand Down Expand Up @@ -81,6 +83,17 @@ public static void writeWaveFileHeader(FileOutputStream out,
out.write(header, 0, 44);
}

public static Thread getRecorderThread(final AudioRecord recorder,
final boolean isRecording) {
return new Thread(new Runnable() {

@Override
public void run() {
WaveWriter.writeAudioDataToFile(recorder, isRecording);
}
}, WaveWriter.AUDIO_RECORDER_THREAD_NAME);
}

public static void copyWaveFile(String inFilename, String outFilename) {
FileInputStream in = null;
FileOutputStream out = null;
Expand Down
56 changes: 20 additions & 36 deletions app/Locabean/src/com/locaudio/locabean/NodeActivity.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
package com.locaudio.locabean;

import java.io.IOException;
import java.util.Arrays;

import org.apache.http.client.ClientProtocolException;

import android.app.Activity;
import android.media.AudioRecord;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
Expand All @@ -19,17 +13,17 @@
import com.locaudio.api.Locaudio;
import com.locaudio.api.NotifyForm;
import com.locaudio.api.NotifyResponse;
import com.locaudio.api.SoundLocation;

public class NodeActivity extends Activity {

private AudioRecord recorder = null;
private Thread recordingThread = null;
private boolean isRecording = false;
private TextView fingerprintTextView = null;
private TextView nameTextView = null;
private TextView confidenceTextView = null;
private Locaudio locaudio = null;

private static final String IP_ADDRESS = "192.168.1.9";
private static final String IP_ADDRESS = "10.0.0.221";// "192.168.1.9";
private static final int PORT = 8000;

@Override
Expand All @@ -39,15 +33,17 @@ public void onCreate(Bundle savedInstanceState) {

setButtonHandlers();
enableButtons(false);
fingerprintTextView = (TextView) findViewById(R.id.fingerprintText);
fingerprintTextView.setMovementMethod(new ScrollingMovementMethod());

nameTextView = (TextView) findViewById(R.id.nameTextView);
confidenceTextView = (TextView) findViewById(R.id.confidenceTextView);

locaudio = new Locaudio(IP_ADDRESS, PORT);
}

private void setButtonHandlers() {
((Button) findViewById(R.id.btnStart)).setOnClickListener(btnClick);
((Button) findViewById(R.id.btnStop)).setOnClickListener(btnClick);
((Button) findViewById(R.id.btnSend)).setOnClickListener(btnClick);
}

private void enableButton(int id, boolean isEnable) {
Expand All @@ -68,13 +64,7 @@ private void startRecording() {

isRecording = true;

recordingThread = new Thread(new Runnable() {

@Override
public void run() {
WaveWriter.writeAudioDataToFile(recorder, isRecording);
}
}, "AudioRecorder Thread");
recordingThread = WaveWriter.getRecorderThread(recorder, isRecording);

recordingThread.start();
}
Expand All @@ -84,8 +74,10 @@ private void stopRecording() {
isRecording = false;

int i = recorder.getState();
if (i == 1)
if (i == WaveWriter.AUDIO_RECORDER_ON_STATE) {
recorder.stop();
}

recorder.release();

recorder = null;
Expand Down Expand Up @@ -115,30 +107,22 @@ public void onClick(View v) {
enableButtons(false);
stopRecording();

Wave wave = new Wave(WaveWriter.getFilename());
fingerprintTextView.setText(Arrays.toString(wave
.getFingerprint()));

SoundLocation[] soundLocations = locaudio
.getSoundLocations("Cock");
System.out.println(Arrays.toString(soundLocations));
break;
}
case R.id.btnSend: {

Wave wave = new Wave(WaveWriter.getFilename());
NotifyForm postForm = new NotifyForm();
postForm.setFingerprint(wave.getFingerprint());
postForm.setSoundPressureLevel(100);
postForm.setTimestamp(10);
postForm.setX(1);
postForm.setY(0);

try {
NotifyResponse nr = locaudio.notifyEvent(postForm);
System.out.println(nr.name);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}


NotifyResponse nr = locaudio.notifyEvent(postForm);
nameTextView.setText(nr.name);
confidenceTextView.setText("" + nr.confidence);

break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import locaudio.api as api


server_addr = "192.168.1.9"
server_addr = "10.0.0.221" #"192.168.1.9"
server_port = 8000

test_sound_name = "Cock"
Expand Down

0 comments on commit cce8084

Please sign in to comment.