Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ dependencies {
compile 'com.segway.robot:basesdk:0.6.376'
compile 'com.segway.robot:robot-connectivity-sdk:0.5.98'
compile 'com.segway.robot:emoji:0.1.28'
compile 'com.google.android.gms:play-services-base:12.0.0'
//compile 'com.google.android.gms:play-services-base:15.0.0'
compile 'com.google.cloud:google-cloud-speech:0.42.1-alpha'

annotationProcessor 'com.google.auto.value:auto-value:1.2'

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />

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

<application
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
package de.iteratec.slab.segway.remote.robot;

import android.content.Context;
import android.media.MediaRecorder;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.content.*;
import android.widget.Toast;
import android.speech.*;

import com.google.cloud.speech.v1.RecognitionAudio;
import com.google.cloud.speech.v1.RecognitionConfig;
import com.google.cloud.speech.v1.RecognizeResponse;
import com.google.cloud.speech.v1.SpeechClient;
import com.google.cloud.speech.v1.SpeechRecognitionAlternative;
import com.google.cloud.speech.v1.SpeechRecognitionResult;
import com.google.common.primitives.Bytes;
import com.google.protobuf.ByteString;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Locale;
import java.util.ArrayList;

import de.iteratec.slab.segway.remote.robot.service.LoomoBaseService;
import de.iteratec.slab.segway.remote.robot.service.LoomoConnectivityService;
Expand All @@ -29,6 +56,10 @@ public class MainActivity extends AppCompatActivity {
private LoomoEmojiService loomoEmojiService;
private LoomoConnectivityService loomoConnectionService;

private Button recordButton;
private MediaRecorder mRecorder = null;

private final int REQ_CODE_SPEECH_INPUT = 100;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -37,16 +68,74 @@ protected void onCreate(Bundle savedInstanceState) {

statusText = (TextView) findViewById(R.id.status_text);

recordButton = (Button) findViewById(R.id.button);
recordButton.setOnClickListener(recordListener);

// Hides the status bar
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
getSupportActionBar().hide();

mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setOutputFile(getExternalCacheDir().getAbsolutePath() + "/test.3gpp");
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);


initStatus();
initServices();
}

private Boolean recording = true;

public View.OnClickListener recordListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
promptSpeechInput();
}
};

private void promptSpeechInput() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
//intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
//RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
//intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
try {
startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);

} catch (ActivityNotFoundException a) {
Toast.makeText(getApplicationContext(),"empty",
Toast.LENGTH_SHORT).show();
Log.i(TAG, "here", a);

}
}

/**
* Receiving speech input
* */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

switch (requestCode) {
case REQ_CODE_SPEECH_INPUT: {
if (resultCode == RESULT_OK && null != data) {

ArrayList<String> result = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
Toast.makeText(getApplicationContext(),(result.get(0)),
Toast.LENGTH_LONG).show();
}
break;
}

}
}


private void initStatus() {
String ip = getDeviceIp();
statusText.setText("My Ip: " + ip);
Expand Down Expand Up @@ -86,5 +175,6 @@ protected void onDestroy() {
this.loomoVisionService.disconnect();
this.loomoHeadService.disconnect();
this.loomoRecognitionService.disconnect();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.content.res.AssetManager;
import android.os.AsyncTask;
import android.util.Log;

import com.android.volley.Request;
Expand All @@ -10,6 +11,18 @@
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.google.api.gax.core.CredentialsProvider;
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.auth.oauth2.ServiceAccountCredentials;
import com.google.cloud.speech.v1.RecognitionAudio;
import com.google.cloud.speech.v1.RecognitionConfig;
import com.google.cloud.speech.v1.RecognizeResponse;
import com.google.cloud.speech.v1.SpeechClient;
import com.google.cloud.speech.v1.SpeechRecognitionAlternative;
import com.google.cloud.speech.v1.SpeechRecognitionResult;
import com.google.cloud.speech.v1.SpeechSettings;
import com.google.protobuf.ByteString;
import com.segway.robot.sdk.base.bind.ServiceBinder;
import com.segway.robot.sdk.voice.Recognizer;
import com.segway.robot.sdk.voice.VoiceException;
Expand All @@ -20,6 +33,9 @@
import com.segway.robot.sdk.voice.recognition.WakeupListener;
import com.segway.robot.sdk.voice.recognition.WakeupResult;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
Expand All @@ -36,6 +52,7 @@ public class LoomoRecognitionService {
private static final String TAG = "LoomoRecognitionService";
public static final float MOVE_DELTA = 0.5f;
private final Context context;
private SpeechClient speechClient;

private Recognizer recognizer;
private RequestQueue queue;
Expand Down Expand Up @@ -210,6 +227,8 @@ public void onErrorResponse(VolleyError error) {
loomoBaseService.resetPosition();

}
} else {
Log.d(TAG, "unknown command:" + recognitionResult);
}
return false;
}
Expand Down Expand Up @@ -255,6 +274,12 @@ public void disconnect() {
if (this.queue != null) {
this.queue.cancelAll(TAG);
}
try {
this.speechClient.close();
} catch (Exception e) {
e.printStackTrace();
}

this.recognizer.unbindService();
}
}
6 changes: 6 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
android:orientation="vertical"
tools:context="de.iteratec.slab.segway.remote.robot.MainActivity">

<Button
android:id="@+id/button"
android:text="Record"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<ViewSwitcher
android:id="@+id/view_switcher"
android:layout_width="match_parent"
Expand Down
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ buildscript {
url 'https://maven.google.com/'
name 'Google'
}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:3.1.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Dec 18 17:10:47 CET 2017
#Mon Apr 23 13:56:19 CEST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip