Include waveform when sending voice messages (#1650)

- New `AudioLevelCalculator` that outputs dB0v rescaled to the [0;1] range.
- `VoiceRecorder` now stores the audio levels sampled while recording, then resamples them to 100 samples to use as waveform preview.
- Waveform data is carried all the way as a `List<Float>` and converted to `List<Int>` in the [0;1024] range as per matrix spec only before sending it.
This commit is contained in:
Marco Romano 2023-10-26 17:37:24 +02:00 committed by GitHub
parent a67410f573
commit 00d24ce4b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 199 additions and 70 deletions

View file

@ -148,6 +148,7 @@ class VoiceMessageComposerPresenter @Inject constructor(
appCoroutineScope.sendMessage(
file = finishedState.file,
mimeType = finishedState.mimeType,
waveform = finishedState.waveform,
).invokeOnCompletion {
isSending = false
}
@ -207,12 +208,14 @@ class VoiceMessageComposerPresenter @Inject constructor(
}
private fun CoroutineScope.sendMessage(
file: File, mimeType: String,
file: File,
mimeType: String,
waveform: List<Float>
) = launch {
val result = mediaSender.sendVoiceMessage(
uri = file.toUri(),
mimeType = mimeType,
waveForm = emptyList(), // TODO generate waveform
waveForm = waveform.toMSC3246range(),
)
if (result.isFailure) {
@ -223,3 +226,8 @@ class VoiceMessageComposerPresenter @Inject constructor(
voiceRecorder.deleteRecording()
}
}
/**
* Resizes the given [0;1] float list to [0;1024] int list as per unstable MSC3246 spec.
*/
private fun List<Float>.toMSC3246range(): List<Int> = map { (it * 1024).toInt() }