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 val themeOption: MutableState<ThemeOption?> = mutableStateOf(null)
private fun updateContent() { 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 { setContent {
themeOption.value?.let { themeOption -> themeOption.value?.let { themeOption ->
val themeIdx = useDataStore(key = THEME_KEY.key, default = themeOption.key) 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 * This function converts input audio samples to 1x80x3000 features
*/ */
fun melSpectrogram(y: DoubleArray): FloatArray { 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) { if (it < y.size) {
y[it] y[it]
} else { } else {

View File

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