Update melSpectrogram

This commit is contained in:
Aleksandras Kostarevas 2023-09-27 23:05:27 +03:00
parent f1ff995cc7
commit a88bd5c820
3 changed files with 4 additions and 8 deletions

View File

@ -256,6 +256,8 @@ class DownloadActivity : ComponentActivity() {
private val themeOption: MutableState<ThemeOption?> = mutableStateOf(null)
private fun updateContent() {
// TODO: In some cases seems to cause a crash?
// May be related https://github.com/mozilla-mobile/focus-android/issues/7712
setContent {
themeOption.value?.let { themeOption ->
val themeIdx = useDataStore(key = THEME_KEY.key, default = themeOption.key)

View File

@ -209,7 +209,7 @@ class AudioFeatureExtraction(
* This function converts input audio samples to 1x80x3000 features
*/
fun melSpectrogram(y: DoubleArray): FloatArray {
val paddedWaveform = DoubleArray(min(numSamples, y.size + hopLength)) {
val paddedWaveform = DoubleArray(min(numSamples, y.size + hopLength).coerceAtLeast(nFFT)) {
if (it < y.size) {
y[it]
} else {

View File

@ -12,11 +12,5 @@ private val extractor = AudioFeatureExtraction(
)
fun extractMelSpectrogramForWhisper(samples: DoubleArray): FloatArray {
val paddedSamples = if(samples.size <= 640) {
samples + DoubleArray(640) { 0.0 }
} else {
samples
}
return extractor.melSpectrogram(paddedSamples)
return extractor.melSpectrogram(samples)
}