Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LatinIME
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
keyboard
LatinIME
Commits
39b46adc
Commit
39b46adc
authored
1 year ago
by
Aleksandras Kostarevas
Browse files
Options
Downloads
Patches
Plain Diff
Disable whisper.cpp pending futher work
parent
4e9e86d8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!7
Merge model-metadata to master
,
!4
Merge lm-2-finetuning-whisperggml into lm-2-finetuning
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
voiceinput-shared/src/main/java/org/futo/voiceinput/shared/AudioRecognizer.kt
+4
-34
4 additions, 34 deletions
...c/main/java/org/futo/voiceinput/shared/AudioRecognizer.kt
with
4 additions
and
34 deletions
voiceinput-shared/src/main/java/org/futo/voiceinput/shared/AudioRecognizer.kt
+
4
−
34
View file @
39b46adc
...
...
@@ -4,7 +4,6 @@ import android.Manifest
import
android.content.Context
import
android.content.Intent
import
android.content.pm.PackageManager
import
android.content.res.AssetManager
import
android.hardware.SensorPrivacyManager
import
android.media.AudioFormat
import
android.media.AudioRecord
...
...
@@ -25,7 +24,6 @@ import kotlinx.coroutines.Job
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.withContext
import
kotlinx.coroutines.yield
import
org.futo.voiceinput.shared.ggml.WhisperGGML
import
org.futo.voiceinput.shared.types.AudioRecognizerListener
import
org.futo.voiceinput.shared.types.InferenceState
import
org.futo.voiceinput.shared.types.Language
...
...
@@ -35,17 +33,14 @@ import org.futo.voiceinput.shared.types.ModelLoader
import
org.futo.voiceinput.shared.whisper.DecodingConfiguration
import
org.futo.voiceinput.shared.whisper.ModelManager
import
org.futo.voiceinput.shared.whisper.MultiModelRunConfiguration
import
org.futo.voiceinput.shared.whisper.MultiModelRunner
import
org.futo.voiceinput.shared.whisper.isBlankResult
import
org.tensorflow.lite.support.common.FileUtil
import
java.io.FileInputStream
import
java.nio.FloatBuffer
import
java.nio.ShortBuffer
import
java.nio.channels.FileChannel
import
kotlin.math.min
import
kotlin.math.pow
import
kotlin.math.sqrt
data class
AudioRecognizerSettings
(
val
modelRunConfiguration
:
MultiModelRunConfiguration
,
val
decodingConfiguration
:
DecodingConfiguration
...
...
@@ -63,16 +58,13 @@ class AudioRecognizer(
private
var
isRecording
=
false
private
var
recorder
:
AudioRecord
?
=
null
//
private val modelRunner = MultiModelRunner(modelManager)
private
val
modelRunner
=
MultiModelRunner
(
modelManager
)
private
val
floatSamples
:
FloatBuffer
=
FloatBuffer
.
allocate
(
16000
*
30
)
private
var
recorderJob
:
Job
?
=
null
private
var
modelJob
:
Job
?
=
null
private
var
loadModelJob
:
Job
?
=
null
private
val
buffer
=
FileUtil
.
loadMappedFile
(
context
,
"ggml-model.tflite"
)
private
val
ggmlModel
=
WhisperGGML
(
buffer
)
@Throws
(
ModelDoesNotExistException
::
class
)
private
fun
verifyModelsExist
()
{
val
modelsThatDoNotExist
=
mutableListOf
<
ModelLoader
>()
...
...
@@ -171,7 +163,7 @@ class AudioRecognizer(
}
private
suspend
fun
preloadModels
()
{
//
modelRunner.preload(settings.modelRunConfiguration)
modelRunner
.
preload
(
settings
.
modelRunConfiguration
)
}
private
suspend
fun
recordingJob
(
recorder
:
AudioRecord
,
vad
:
VadModel
)
{
...
...
@@ -360,26 +352,6 @@ class AudioRecognizer(
}
private
suspend
fun
runModel
()
{
val
floatArray
=
floatSamples
.
array
().
sliceArray
(
0
until
floatSamples
.
position
())
yield
()
val
outputText
=
ggmlModel
.
infer
(
floatArray
).
trim
()
val
text
=
when
{
isBlankResult
(
outputText
)
->
""
else
->
outputText
}
yield
()
lifecycleScope
.
launch
{
withContext
(
Dispatchers
.
Main
)
{
yield
()
listener
.
finished
(
text
)
}
}
/*
loadModelJob
?.
let
{
if
(
it
.
isActive
)
{
println
(
"Model was not finished loading..."
)
...
...
@@ -387,7 +359,7 @@ class AudioRecognizer(
}
}
val
floatArray
=
floatSamples
.
array
().
sliceArray
(
0
until
floatSamples
.
position
())
yield
()
val
outputText
=
modelRunner
.
run
(
...
...
@@ -409,8 +381,6 @@ class AudioRecognizer(
listener
.
finished
(
text
)
}
}
*/
}
private
fun
onFinishRecording
()
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment