Skip to content

Commit 2d333ba

Browse files
committed
Speech Recognition
0 parents  commit 2d333ba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1066
-0
lines changed

.gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties

.idea/.gitignore

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/compiler.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

+18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/kotlinc.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LICENSE

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright 2023
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

NOTICE

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Apache CustomBadge
2+
Copyright 2023 The Apache Software Foundation
3+
4+
This product includes software developed at
5+
The Apache Software Foundation (http://www.apache.org/).

Screens/Screen_Arabic.gif

955 KB
Loading

Screens/Screen_English.gif

1.08 MB
Loading

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
plugins {
2+
id 'com.android.application'
3+
id 'org.jetbrains.kotlin.android'
4+
id 'kotlin-kapt'
5+
}
6+
7+
android {
8+
9+
namespace 'com.orbitalsonic.speechrecognition'
10+
compileSdk 33
11+
12+
defaultConfig {
13+
applicationId "com.orbitalsonic.speechrecognition"
14+
minSdk 23
15+
targetSdk 33
16+
versionCode 1
17+
versionName "1.0"
18+
19+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
20+
}
21+
22+
buildTypes {
23+
release {
24+
minifyEnabled false
25+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
26+
}
27+
}
28+
compileOptions {
29+
sourceCompatibility JavaVersion.VERSION_17
30+
targetCompatibility JavaVersion.VERSION_17
31+
}
32+
kotlinOptions {
33+
jvmTarget = '17'
34+
}
35+
buildFeatures {
36+
dataBinding true
37+
viewBinding true
38+
}
39+
}
40+
41+
dependencies {
42+
43+
implementation 'androidx.core:core-ktx:1.8.0'
44+
implementation 'androidx.appcompat:appcompat:1.6.1'
45+
implementation 'com.google.android.material:material:1.5.0'
46+
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
47+
testImplementation 'junit:junit:4.13.2'
48+
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
49+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
50+
51+
//Lottie lib
52+
implementation 'com.airbnb.android:lottie:5.2.0'
53+
}

app/proguard-rules.pro

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.orbitalsonic.speechrecognition
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class ExampleInstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22+
assertEquals("com.orbitalsonic.speechrecognition", appContext.packageName)
23+
}
24+
}

app/src/main/AndroidManifest.xml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<uses-permission android:name="android.permission.RECORD_AUDIO" />
6+
7+
<application
8+
android:allowBackup="true"
9+
android:dataExtractionRules="@xml/data_extraction_rules"
10+
android:fullBackupContent="@xml/backup_rules"
11+
android:icon="@mipmap/ic_launcher"
12+
android:label="@string/app_name"
13+
android:roundIcon="@mipmap/ic_launcher_round"
14+
android:supportsRtl="true"
15+
android:theme="@style/Theme.SpeechRecognition"
16+
tools:targetApi="31">
17+
<activity
18+
android:name=".MainActivity"
19+
android:exported="true">
20+
<intent-filter>
21+
<action android:name="android.intent.action.MAIN" />
22+
23+
<category android:name="android.intent.category.LAUNCHER" />
24+
</intent-filter>
25+
</activity>
26+
</application>
27+
28+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package com.orbitalsonic.speechrecognition
2+
3+
import android.content.pm.PackageManager
4+
import android.os.Bundle
5+
import android.view.View
6+
import android.widget.Toast
7+
import androidx.appcompat.app.AppCompatActivity
8+
import androidx.core.app.ActivityCompat
9+
import androidx.core.content.ContextCompat
10+
import com.orbitalsonic.speechrecognition.databinding.ActivityMainBinding
11+
12+
class MainActivity : AppCompatActivity(),onRecognitionListener {
13+
14+
private lateinit var binding: ActivityMainBinding
15+
16+
private lateinit var speechToTextConverter: SpeechToTextConverter
17+
18+
override fun onCreate(savedInstanceState: Bundle?) {
19+
super.onCreate(savedInstanceState)
20+
binding = ActivityMainBinding.inflate(layoutInflater)
21+
setContentView(binding.root)
22+
23+
speechToTextConverter = SpeechToTextConverter(this,this)
24+
25+
// Request microphone permission if not granted already
26+
if (ContextCompat.checkSelfPermission(
27+
this,
28+
android.Manifest.permission.RECORD_AUDIO
29+
) != PackageManager.PERMISSION_GRANTED
30+
) {
31+
ActivityCompat.requestPermissions(
32+
this,
33+
arrayOf(android.Manifest.permission.RECORD_AUDIO),
34+
1
35+
)
36+
}
37+
binding.btnSpeak.setOnClickListener {
38+
// Start listening
39+
// speechToTextConverter.startListening("en-US")
40+
// speechToTextConverter.startListening("es-ES")
41+
// speechToTextConverter.startListening("hi")
42+
// speechToTextConverter.startListening("ar")
43+
// speechToTextConverter.startListening("ur")
44+
speechToTextConverter.startListening("en")
45+
}
46+
}
47+
48+
override fun onDestroy() {
49+
super.onDestroy()
50+
// Stop listening
51+
speechToTextConverter.stopListening()
52+
}
53+
54+
override fun onReadyForSpeech() {
55+
binding.btnSpeak.visibility = View.GONE
56+
binding.tvResult.visibility = View.GONE
57+
binding.tvMessage.visibility = View.VISIBLE
58+
binding.lavMicAnimation.visibility = View.VISIBLE
59+
}
60+
override fun onBeginningOfSpeech() {}
61+
override fun onEndOfSpeech() {}
62+
override fun onError(error: String) {
63+
Toast.makeText(this, error, Toast.LENGTH_SHORT).show()
64+
binding.btnSpeak.visibility = View.VISIBLE
65+
binding.tvResult.visibility = View.VISIBLE
66+
binding.tvResult.text = "Sorry, Please try again"
67+
binding.tvMessage.visibility = View.GONE
68+
binding.lavMicAnimation.visibility = View.GONE
69+
}
70+
71+
override fun onResults(results: String) {
72+
binding.btnSpeak.visibility = View.VISIBLE
73+
binding.tvResult.visibility = View.VISIBLE
74+
binding.tvMessage.visibility = View.GONE
75+
binding.lavMicAnimation.visibility = View.GONE
76+
binding.tvResult.text = results
77+
}
78+
79+
80+
}

0 commit comments

Comments
 (0)