little changes
This commit is contained in:
parent
c5ee9b6bbf
commit
0bfb13f678
.idea/caches
app/src/main
java/adrienmalin/pingpoints
res
BIN
.idea/caches/build_file_checksums.ser
generated
BIN
.idea/caches/build_file_checksums.ser
generated
Binary file not shown.
@ -9,65 +9,37 @@ import android.speech.RecognitionListener
|
|||||||
import android.speech.RecognizerIntent
|
import android.speech.RecognizerIntent
|
||||||
import android.speech.SpeechRecognizer
|
import android.speech.SpeechRecognizer
|
||||||
import android.support.v4.app.DialogFragment
|
import android.support.v4.app.DialogFragment
|
||||||
import android.util.Log
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.widget.ImageView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import kotlin.math.max
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
class SttDialog : DialogFragment() {
|
class SttDialog : DialogFragment() {
|
||||||
var partialResultsTextView: TextView? = null
|
|
||||||
var matchActivity: MatchActivity? = null
|
var matchActivity: MatchActivity? = null
|
||||||
|
var partialResultsTextView: TextView? = null
|
||||||
|
var icStt: ImageView? = null
|
||||||
var stt: SpeechRecognizer? = null
|
var stt: SpeechRecognizer? = null
|
||||||
var sttIntent: Intent? = null
|
var sttIntent: Intent? = null
|
||||||
|
|
||||||
inner class SttListener : RecognitionListener {
|
inner class SttListener : RecognitionListener {
|
||||||
val LOG_TAG: String = "SttListener"
|
var minRms: Float = 0f
|
||||||
|
var maxRms: Float = 0f
|
||||||
|
|
||||||
override fun onBeginningOfSpeech() {
|
override fun onRmsChanged(rmsdB: Float) {
|
||||||
Log.i(LOG_TAG, "onBeginningOfSpeech")
|
minRms = min(rmsdB, minRms)
|
||||||
}
|
maxRms = max(rmsdB, maxRms)
|
||||||
|
if (minRms != maxRms)
|
||||||
override fun onBufferReceived(buffer: ByteArray?) {
|
icStt?.alpha = 0.5f + rmsdB / (2*(maxRms - minRms))
|
||||||
Log.i(LOG_TAG, "onBufferReceived: $buffer");
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onEndOfSpeech() {
|
|
||||||
Log.i(LOG_TAG, "onEndOfSpeech")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onError(errorCode: Int) {
|
|
||||||
val errorMessage: String = when (errorCode) {
|
|
||||||
SpeechRecognizer.ERROR_AUDIO -> "Audio recording error"
|
|
||||||
SpeechRecognizer.ERROR_CLIENT -> "Client side error"
|
|
||||||
SpeechRecognizer.ERROR_INSUFFICIENT_PERMISSIONS -> "Insufficient permissions"
|
|
||||||
SpeechRecognizer.ERROR_NETWORK -> "Network error"
|
|
||||||
SpeechRecognizer.ERROR_NETWORK_TIMEOUT -> "Network timeout"
|
|
||||||
SpeechRecognizer.ERROR_NO_MATCH -> "No match"
|
|
||||||
SpeechRecognizer.ERROR_RECOGNIZER_BUSY -> "RecognitionService busy"
|
|
||||||
SpeechRecognizer.ERROR_SERVER -> "error from server"
|
|
||||||
SpeechRecognizer.ERROR_SPEECH_TIMEOUT -> "No speech input"
|
|
||||||
else -> "Didn't understand, please try again."
|
|
||||||
}
|
|
||||||
Log.d(LOG_TAG, "FAILED $errorMessage")
|
|
||||||
stt?.startListening(sttIntent)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onEvent(arg0: Int, arg1: Bundle?) {
|
|
||||||
Log.i(LOG_TAG, "onEvent")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPartialResults(data: Bundle) {
|
override fun onPartialResults(data: Bundle) {
|
||||||
//Log.i(LOG_TAG, "onPartialResults")
|
|
||||||
partialResultsTextView?.text = data.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION)[0]
|
partialResultsTextView?.text = data.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION)[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onReadyForSpeech(arg0: Bundle?) {
|
|
||||||
Log.i(LOG_TAG, "onReadyForSpeech")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onResults(data: Bundle) {
|
override fun onResults(data: Bundle) {
|
||||||
Log.i(LOG_TAG, "onResults");
|
|
||||||
val results: ArrayList<String> = data.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION)
|
val results: ArrayList<String> = data.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION)
|
||||||
var understood = false
|
var understood = false
|
||||||
|
|
||||||
@ -86,16 +58,22 @@ class SttDialog : DialogFragment() {
|
|||||||
if (understood) break
|
if (understood) break
|
||||||
}
|
}
|
||||||
if (!understood) {
|
if (!understood) {
|
||||||
partialResultsTextView?.text = getString(R.string.not_understood)
|
onError(0)
|
||||||
stt?.startListening(sttIntent)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onRmsChanged(rmsdB: Float) {
|
override fun onError(errorCode: Int) {
|
||||||
//Log.i(LOG_TAG, "onRmsChanged: $rmsdB")
|
partialResultsTextView?.text = getString(R.string.not_understood)
|
||||||
|
stt?.startListening(sttIntent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onEvent(arg0: Int, arg1: Bundle?) {}
|
||||||
|
override fun onReadyForSpeech(arg0: Bundle?) {}
|
||||||
|
override fun onBeginningOfSpeech() {}
|
||||||
|
override fun onBufferReceived(buffer: ByteArray?) {}
|
||||||
|
override fun onEndOfSpeech() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateDialog(savedInstanceState: Bundle?) = AlertDialog.Builder(activity).apply {
|
override fun onCreateDialog(savedInstanceState: Bundle?) = AlertDialog.Builder(activity).apply {
|
||||||
@ -104,6 +82,7 @@ class SttDialog : DialogFragment() {
|
|||||||
null
|
null
|
||||||
)
|
)
|
||||||
partialResultsTextView = view.findViewById(R.id.partialResultTextView)
|
partialResultsTextView = view.findViewById(R.id.partialResultTextView)
|
||||||
|
icStt = view.findViewById(R.id.icStt)
|
||||||
|
|
||||||
setView(view)
|
setView(view)
|
||||||
|
|
||||||
|
@ -5,7 +5,8 @@
|
|||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent"
|
||||||
|
android:keepScreenOn="true">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -5,7 +5,8 @@
|
|||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent"
|
||||||
|
android:keepScreenOn="true">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -80,7 +81,7 @@
|
|||||||
app:layout_constraintStart_toEndOf="@+id/imgService0"
|
app:layout_constraintStart_toEndOf="@+id/imgService0"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
tools:text="@string/button_text" android:layout_margin="8dp" android:layout_weight="1"
|
tools:text="@string/button_text" android:layout_margin="8dp" android:layout_weight="1"
|
||||||
android:theme="@style/ScoreButton"/>
|
android:theme="@style/ScoreButton" android:layout_marginLeft="8dp"/>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/buttonPlayer1"
|
android:id="@+id/buttonPlayer1"
|
||||||
@ -126,7 +127,6 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/iconCredits"
|
android:text="@string/iconCredits"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/PingPointsCredit"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
android:layout_marginStart="8dp" app:layout_constraintEnd_toEndOf="parent"
|
android:layout_marginStart="8dp" app:layout_constraintEnd_toEndOf="parent"
|
||||||
android:layout_marginEnd="8dp"
|
android:layout_marginEnd="8dp"
|
||||||
|
@ -13,12 +13,14 @@
|
|||||||
<ImageView
|
<ImageView
|
||||||
app:srcCompat="@drawable/ic_stt"
|
app:srcCompat="@drawable/ic_stt"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" android:id="@+id/imageView" android:layout_margin="8dp"/>
|
android:layout_height="wrap_content" android:id="@+id/icStt" android:layout_margin="8dp"
|
||||||
|
android:contentDescription="@string/STT"/>
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/STT_hint" android:id="@+id/sttHintTextView" android:layout_margin="8dp"
|
android:text="@string/STT_hint" android:id="@+id/sttHintTextView"
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium" android:gravity="center"/>
|
android:textAppearance="@style/TextAppearance.AppCompat.Medium" android:gravity="center"
|
||||||
|
android:layout_marginLeft="8dp" android:layout_marginRight="8dp"/>
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" android:id="@+id/partialResultTextView"
|
android:layout_height="wrap_content" android:id="@+id/partialResultTextView"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user