ADded the punctuation sections to the code - but have not added the zip extraction to include this automatically - might ahve to add another upload manager specifically for this one file I think, as it is really messy to get your hands on through other means....
This commit is contained in:
@@ -11,8 +11,8 @@ android {
|
||||
applicationId = "net.mmanningau.speechtokeyboard"
|
||||
minSdk = 28
|
||||
targetSdk = 36
|
||||
versionCode = 10
|
||||
versionName = "1.0"
|
||||
versionCode = 11
|
||||
versionName = "1.1"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
@@ -27,6 +27,10 @@ import com.k2fsa.sherpa.onnx.OnlineTransducerModelConfig
|
||||
import com.k2fsa.sherpa.onnx.OnlineStream
|
||||
import java.io.File
|
||||
|
||||
import com.k2fsa.sherpa.onnx.OfflinePunctuation
|
||||
import com.k2fsa.sherpa.onnx.OfflinePunctuationConfig
|
||||
import com.k2fsa.sherpa.onnx.OfflinePunctuationModelConfig
|
||||
|
||||
class TestModelActivity : AppCompatActivity() {
|
||||
|
||||
// UI Components
|
||||
@@ -39,6 +43,9 @@ class TestModelActivity : AppCompatActivity() {
|
||||
private var isRecording = false
|
||||
private var recordingThread: Thread? = null
|
||||
|
||||
// Punctuation variables
|
||||
private var punctuator: OfflinePunctuation? = null
|
||||
|
||||
// USB Components
|
||||
private var usbPort: UsbSerialPort? = null
|
||||
|
||||
@@ -117,6 +124,23 @@ class TestModelActivity : AppCompatActivity() {
|
||||
|
||||
outputText.text = "Engine Loaded. Ready to Stream."
|
||||
|
||||
// ... existing recognizer init code ...
|
||||
|
||||
// 5. Initialize Punctuation Engine
|
||||
val punctPath = File(modelDir, "punct_model.onnx").absolutePath
|
||||
|
||||
if (File(punctPath).exists()) {
|
||||
// CORRECTED: Wrap the path inside 'OfflinePunctuationModelConfig'
|
||||
val punctConfig = OfflinePunctuationConfig(
|
||||
model = OfflinePunctuationModelConfig(ctTransformer = punctPath)
|
||||
)
|
||||
|
||||
punctuator = OfflinePunctuation(config = punctConfig)
|
||||
outputText.append("\n+ Punctuation Ready")
|
||||
} else {
|
||||
outputText.append("\n(No Punctuation model found)")
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
Log.e("Sherpa", "Init Error", e)
|
||||
outputText.text = "Init Error: ${e.message}"
|
||||
@@ -205,10 +229,15 @@ class TestModelActivity : AppCompatActivity() {
|
||||
// FIX 2: THE ORDER OF OPERATIONS
|
||||
|
||||
// A. Update UI first
|
||||
// 1. PUNCTUATE
|
||||
// We pass the raw text to the punctuator
|
||||
val punctuatedText = punctuator?.addPunctuation(cleanText) ?: cleanText
|
||||
|
||||
runOnUiThread {
|
||||
committedText += "$cleanText "
|
||||
// 2. Commit the BEAUTIFUL text
|
||||
committedText += "$punctuatedText "
|
||||
outputText.text = committedText
|
||||
sendToPico("$cleanText ")
|
||||
sendToPico("$punctuatedText ")
|
||||
}
|
||||
|
||||
// B. RESET IMMEDIATELY ON BACKGROUND THREAD
|
||||
|
||||
Reference in New Issue
Block a user