Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
aa516b2
Initial commit
deekshithreddyr Jul 10, 2019
ad096da
Addressed review comments
deekshithreddyr Jul 16, 2019
2a0b27f
Added README File
deekshithreddyr Jul 16, 2019
bbd9f4e
Update README.md
deekshithreddyr Jul 17, 2019
a4f9ba8
Update README.md
deekshithreddyr Jul 17, 2019
b33d644
Update README.md
deekshithreddyr Jul 17, 2019
6ce8859
refactor: refactoring the code
deekshithreddyr Jul 21, 2019
0f862d4
Merge branch 'master' of https://github.com/deekshithreddyr/android-d…
deekshithreddyr Jul 21, 2019
2e38050
Add stopwatchagent.zip file
deekshithreddyr Jul 21, 2019
c3c2b78
Update README.md
deekshithreddyr Jul 22, 2019
bba436b
Update README.md
deekshithreddyr Jul 22, 2019
b168253
Changes has per Github comments
deekshithreddyr Jul 23, 2019
e7d5487
Combine the three requests into one. Dropdown instead of multi-selec…
deekshithreddyr Aug 6, 2019
9dcf0d1
Addressed review comments
deekshithreddyr Aug 8, 2019
9ddd430
Using the Audio returned from Dialogflow.
deekshithreddyr Aug 11, 2019
1c2b79f
Addressed review comments
deekshithreddyr Aug 13, 2019
462db73
Separated the Authentication code from AppController.java to AuthUtil…
deekshithreddyr Aug 14, 2019
c8371eb
Code Refinement
deekshithreddyr Aug 18, 2019
20b798a
Update README.md
deekshithreddyr Aug 18, 2019
d31ecb6
Update README.md
deekshithreddyr Aug 19, 2019
cafff50
Addressed review comments
deekshithreddyr Aug 26, 2019
6b8e4bd
Merge branch 'master' of https://github.com/deekshithreddyr/android-d…
deekshithreddyr Aug 26, 2019
4dd38b9
function to convert the time from UTC to local TimeZone added
deekshithreddyr Aug 26, 2019
73edd3f
Code readability update
deekshithreddyr Aug 30, 2019
12e2d39
Update README.md
deekshithreddyr Aug 30, 2019
26599e8
Speech2speech Initial commit
deekshithreddyr Aug 30, 2019
32020e9
Merge branch 'master' of https://github.com/deekshithreddyr/android-d…
deekshithreddyr Aug 30, 2019
f6428b3
@nnegrey
nnegrey Sep 16, 2019
b8c8fac
Move sample
nnegrey Sep 19, 2019
7c99053
Update package name
nnegrey Sep 19, 2019
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
13 changes: 13 additions & 0 deletions speech/Speech-to-Speech/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
67 changes: 67 additions & 0 deletions speech/Speech-to-Speech/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Cloud Speech to Speech Translation Sample

This app demonstrates how to create a live translation service using the Cloud Speech-To-Text,
Translation, and Text-To-Speech APIs. It uses these apis to:

- Make streaming gRPC connections to the Cloud Speech API` to recognize speech in recorded audio.
- Send transcripts to the Translate API to get the translation.
- Send translated text to the Text-to-Speech API so that it can be played back to the user.

To call the Dialogflow API from Android, you need provide authorization tokens with each request. To
get this token, this sample uses a Firebase Function to genereate these tokens on the behalf of a
service account. The token is returned to the app via Firebase Cloud Messaging.

## Prerequisites
- An Android device or emulator
- Android Studio 3 or later

## Setup
- Create a project (or use an existing one) in the [Google Cloud Console](https://console.cloud.google.com)
- [Enable billing](https://console.cloud.google.com/billing?project=_) and the
- [Speech API](https://console.cloud.google.com/apis/library/speech.googleapis.com).
- [Translate API](https://console.cloud.google.com/apis/library/translate.googleapis.com).
- [Text-to-Speech API](https://console.cloud.google.com/apis/library/texttospeech.googleapis.com).
- [IAM Service Account Credentials API](https://console.cloud.google.com/apis/library/iamcredentials.googleapis.com).
- [Create a Service account](https://cloud.google.com/iam/docs/creating-managing-service-accounts) with the following IAM role: `Cloud Translation API User`. Example name: `speech-to-speech-client`. ([For more info on: how to add roles to a Service Account](https://cloud.google.com/iam/docs/granting-roles-to-service-accounts#granting_access_to_a_service_account_for_a_resource))

### Setup the app
- Clone this repository `git clone https://github.com/GoogleCloudPlatform/android-docs-samples.git`
- `cd speech/Speech-to-Speech`
- Replace `GCP_PROJECT_ID` in strings.xml with your Project ID

### Setup Firebase on the application:
- Complete the steps for [Add Firebase to your app](https://firebase.google.com/docs/android/setup)
and expand the "Create a Firebase project" section for instructions on how to add project to your
Firebase console. Note: No need to complete any other sections, they are already done.
- In the [Firebase console](https://console.firebase.google.com/), open the "Authentication" section under Develop.
- On the **Sign-in Methods** page, enable the **Anonymous** sign-in method.
- Give the package name of the app as `com.google.cloud.examples.speechtospeech`

### Setup and Deploy the Firebase Function
The Firebase Function provides auth tokens to your app, You'll be using a provided sample function to be run with this app.

- Follow the steps in this [guide](https://firebase.google.com/docs/functions/get-started) for:
- "2. Set up Node.js and the Firebase CLI"
- "3. Initialize Firebase SDK for Cloud Functions".
- Replace `index.js` file with the [provided index.js](https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/master/functions/tokenservice/functions/index.js).
- Open `index.js`, go to the `generateAccessToken` function, and replace`SERVICE-ACCOUNT-NAME@YOUR_PROJECT_ID.iam.gserviceaccount.com` with your Service account name (`speech-to-speech-client`) and project id.
- Deploy getOAuthToken method by running command:
```
firebase deploy --only functions
```
- On the GCP console, add the following IAM role: `Service Account Token Creator` to your
"App Engine Default Service Account" ([For more info on: how to add roles to a Service Account](https://cloud.google.com/iam/docs/granting-roles-to-service-accounts#granting_access_to_a_service_account_for_a_resource))
- Open the [Firebase console](https://console.firebase.google.com/)
- Select Databases on the side menu
- Select Firestore
- Click `Start collection`
- Title your collection `ShortLivedAuthTOkens` and click Next
- Enter `OauthToken` for the Document title and Save
- For more info please refer (https://firebase.google.com/docs/functions/get-started).

## Run the app
- You are now ready to build and run the project. In Android Studio you can do this by clicking the 'Play' button in the toolbar. This will launch the app on the emulator or on the device you've selected.
- As soon the app launches, it will ask for the google sign-in.
- After successful signing in, choose the option by selecting a checkbox and click on chat button
- Type the message to send and click on the send button on the bottom right.
- Alternatively tap on the mic button to speak and send the message to the Dialogflow.
1 change: 1 addition & 0 deletions speech/Speech-to-Speech/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
60 changes: 60 additions & 0 deletions speech/Speech-to-Speech/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
defaultConfig {
applicationId "com.google.cloud.examples.speechtospeech"
minSdkVersion 26
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
exclude 'META-INF/INDEX.LIST'
exclude 'META-INF/io.netty.versions.properties'
}

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.android.support:design:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

implementation 'com.google.firebase:firebase-auth:18.1.0'
implementation 'com.firebaseui:firebase-ui-auth:4.1.0'
implementation 'com.google.firebase:firebase-messaging:19.0.1'
implementation 'com.google.firebase:firebase-functions:18.1.0'

implementation 'com.google.cloud:google-cloud-translate:1.87.0'
implementation group: 'com.google.cloud', name: 'google-cloud-texttospeech', version: '0.45.0-beta'
implementation group: 'com.google.cloud', name: 'google-cloud-speech', version: '1.17.0'

implementation 'com.android.volley:volley:1.1.1'
implementation 'com.google.cloud:google-cloud-dialogflow:0.98.0-alpha'
implementation group: 'io.grpc', name: 'grpc-okhttp', version: '1.21.0'
implementation group: 'io.grpc', name: 'grpc-netty', version: '1.21.0'
}

apply plugin: 'com.google.gms.google-services'
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Sun Aug 25 22:35:10 PDT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
172 changes: 172 additions & 0 deletions speech/Speech-to-Speech/app/gradlew
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
#!/usr/bin/env sh

##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null

APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn () {
echo "$*"
}

die () {
echo
echo "$*"
echo
exit 1
}

# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi

# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi

# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option

if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi

# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "$@"
Loading