@@ -24,15 +24,15 @@ class MainViewModel : ViewModel() {
24
24
lateinit var modelDestFolder: File
25
25
26
26
// Constant strings
27
- private val defaultAudioFileName = " jfk.wav "
27
+ private val defaultAudioFileName = " jfk_441khz.m4a "
28
28
private val whisperFolderName = " openai_whisper-tiny"
29
29
private val microphoneInputFileName = " MicInput.wav"
30
30
31
31
private val _waveFileNamesState = mutableStateOf<List <String >>(emptyList())
32
32
val waveFileNamesState: State <List <String >> get() = _waveFileNamesState
33
33
34
34
var mPlayer: Player ? = null
35
- var waveFile: File ? = null
35
+ lateinit var waveFile: File
36
36
private var mRecorder: Recorder ? = null
37
37
38
38
var sdcardDataFolder: File ? = null
@@ -45,6 +45,15 @@ class MainViewModel : ViewModel() {
45
45
Log .d(" Cache" , cacheDir.absolutePath)
46
46
val nativeLibsDir = context.applicationInfo.nativeLibraryDir
47
47
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
+ }
48
57
loadAudioFileNames(sdcardDataFolder!! .absolutePath)
49
58
50
59
val audioPath = sdcardDataFolder!! .absolutePath + " /" + selectedWavFilename.value
@@ -55,8 +64,6 @@ class MainViewModel : ViewModel() {
55
64
resultState = mutableStateOf(" " )
56
65
statusState = mutableStateOf(" LOADING MODEL (This may take a few minutes when using QNN)" )
57
66
58
- waveFile = File (sdcardDataFolder!! .absolutePath + " /" + microphoneInputFileName)
59
-
60
67
viewModelScope.launch(Dispatchers .IO ) {
61
68
whisperKit = WhisperKitNative (modelDestFolder.absolutePath, audioPath, " ." , nativeLibsDir, 4 )
62
69
statusState.value = " IDLE"
@@ -77,7 +84,14 @@ class MainViewModel : ViewModel() {
77
84
viewModelScope.launch(Dispatchers .IO ) {
78
85
lateinit var transcriptOutput: String
79
86
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
+
81
95
}
82
96
83
97
statusState.value = " IDLE | Last transcript took $time ms"
0 commit comments