Skip to content

Commit 89dd831

Browse files
committed
remove redundant files, safely create mic input file
1 parent ddebbbf commit 89dd831

33 files changed

+45
-6
lines changed

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,11 @@ local.properties
3939
*.hprof
4040

4141
# Log files
42-
*.log
42+
*.log
43+
44+
# test audio files
45+
androidApp/app/src/main/assets/*.wav
46+
androidApp/app/src/main/assets/*.m4a
47+
48+
# .so folder in the app (repeated files)
49+
androidApp/app/src/main/jniLibs
-1.83 MB
Binary file not shown.
-313 KB
Binary file not shown.
-934 KB
Binary file not shown.
-344 KB
Binary file not shown.

androidApp/app/src/main/java/com/whispertflite/MainViewModel.kt

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ class MainViewModel : ViewModel() {
2424
lateinit var modelDestFolder: File
2525

2626
// Constant strings
27-
private val defaultAudioFileName = "jfk.wav"
27+
private val defaultAudioFileName = "jfk_441khz.m4a"
2828
private val whisperFolderName = "openai_whisper-tiny"
2929
private val microphoneInputFileName = "MicInput.wav"
3030

3131
private val _waveFileNamesState = mutableStateOf<List<String>>(emptyList())
3232
val waveFileNamesState: State<List<String>> get() = _waveFileNamesState
3333

3434
var mPlayer: Player? = null
35-
var waveFile: File? = null
35+
lateinit var waveFile: File
3636
private var mRecorder: Recorder? = null
3737

3838
var sdcardDataFolder: File? = null
@@ -45,6 +45,15 @@ class MainViewModel : ViewModel() {
4545
Log.d("Cache", cacheDir.absolutePath)
4646
val nativeLibsDir = context.applicationInfo.nativeLibraryDir
4747
copyDataToSdCardFolder(context)
48+
waveFile = File(sdcardDataFolder!!.absolutePath, microphoneInputFileName)
49+
if (!waveFile.exists()) {
50+
try {
51+
// Create the file
52+
waveFile.createNewFile()
53+
} catch (e: IOException) {
54+
e.printStackTrace() // handle the exception appropriately
55+
}
56+
}
4857
loadAudioFileNames(sdcardDataFolder!!.absolutePath)
4958

5059
val audioPath = sdcardDataFolder!!.absolutePath + "/" + selectedWavFilename.value
@@ -55,8 +64,6 @@ class MainViewModel : ViewModel() {
5564
resultState = mutableStateOf("")
5665
statusState = mutableStateOf("LOADING MODEL (This may take a few minutes when using QNN)")
5766

58-
waveFile = File(sdcardDataFolder!!.absolutePath + "/" + microphoneInputFileName)
59-
6067
viewModelScope.launch(Dispatchers.IO) {
6168
whisperKit = WhisperKitNative(modelDestFolder.absolutePath, audioPath, ".", nativeLibsDir, 4)
6269
statusState.value = "IDLE"
@@ -77,7 +84,14 @@ class MainViewModel : ViewModel() {
7784
viewModelScope.launch(Dispatchers.IO) {
7885
lateinit var transcriptOutput: String
7986
val time = measureTimeMillis {
80-
transcriptOutput = whisperKit.transcribe(sdcardDataFolder!!.absolutePath + "/" + selectedWavFilename.value)
87+
try {
88+
// Create the file
89+
transcriptOutput = whisperKit.transcribe(sdcardDataFolder!!.absolutePath + "/" + selectedWavFilename.value)
90+
} catch (e: IOException) {
91+
e.printStackTrace() // handle the exception appropriately
92+
transcriptOutput = "Transcription ERROR"
93+
}
94+
8195
}
8296

8397
statusState.value = "IDLE | Last transcript took $time ms"
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)