upgrade client Version 5.3 - 7
EBO <eric@ebii.fr> committé le 2026-09-29 20:27
9b9af643dc9773ea288c45edc55f1e88087936a7
1 parent(s)
25 fichiers modifiés
+453
-139
M
android/app/build.gradle.kts
+11
-4
@@ -47,8 +47,8 @@ android {
| 47 | 47 | applicationId = "fr.ebii.piclead" |
| 48 | 48 | minSdk = 30 |
| 49 | 49 | targetSdk = 36 |
| 50 | - versionCode = 6 | |
| 51 | - versionName = "0.5.1" | |
| 50 | + versionCode = 7 | |
| 51 | + versionName = "0.5.2" | |
| 52 | 52 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" |
| 53 | 53 | ndk { |
| 54 | 54 | abiFilters += listOf("arm64-v8a") |
@@ -277,7 +277,14 @@ dependencies {
| 277 | 277 | implementation("androidx.camera:camera-camera2:1.4.1") |
| 278 | 278 | implementation("androidx.camera:camera-lifecycle:1.4.1") |
| 279 | 279 | implementation("androidx.camera:camera-view:1.4.1") |
| 280 | - implementation("org.opencv:opencv:4.10.0") | |
| 280 | + // camera-view tire appcompat 1.1.0, qui tire fragment 1.1.0 — signalé obsolète par le | |
| 281 | + // Play SDK Index (minimum 1.2.1). Contrainte plutôt que dépendance : l'app n'utilise | |
| 282 | + // aucun Fragment. 1.8.9 se satisfait d'activity 1.8.1 / lifecycle 2.6.1, déjà dépassés | |
| 283 | + // ici ; 1.9.x exigerait lifecycle 2.10 et ferait remonter toute la pile. | |
| 284 | + constraints { | |
| 285 | + implementation("androidx.fragment:fragment:1.8.9") | |
| 286 | + } | |
| 287 | + implementation("org.opencv:opencv:4.12.0") | |
| 281 | 288 | implementation("com.github.adaptech-cz.Tesseract4Android:tesseract4android-openmp:4.9.0") |
| 282 | 289 | implementation("androidx.exifinterface:exifinterface:1.3.7") |
| 283 | 290 |
@@ -307,5 +314,5 @@ dependencies {
| 307 | 314 | androidTestImplementation("androidx.test:runner:1.6.2") |
| 308 | 315 | androidTestImplementation("androidx.test:rules:1.6.1") |
| 309 | 316 | |
| 310 | - implementation("com.alphacephei:vosk-android:0.3.47") | |
| 317 | + implementation("com.alphacephei:vosk-android:0.3.70") | |
| 311 | 318 | } |
A
android/app/src/j/AndroidManifest.xml
+7
-0
@@ -0,0 +1,7 @@
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
| 3 | + package="org.vosk" > | |
| 4 | + | |
| 5 | + <uses-sdk android:minSdkVersion="21" /> | |
| 6 | + | |
| 7 | +</manifest> | |
| 7 | < \ No newline at end of file |
A
android/app/src/j/META-INF/com/android/build/gradle/aar-metadata.properties
+6
-0
@@ -0,0 +1,6 @@
| 1 | +aarFormatVersion=1.0 | |
| 2 | +aarMetadataVersion=1.0 | |
| 3 | +minCompileSdk=1 | |
| 4 | +minCompileSdkExtension=0 | |
| 5 | +minAndroidGradlePluginVersion=1.0.0 | |
| 6 | +coreLibraryDesugaringEnabled=false |
A
android/app/src/j/R.txt
+0
-0
A
android/app/src/j/classes.jar
+0
-0
A
android/app/src/j/jni/arm64-v8a/libvosk.so
+0
-0
A
android/app/src/j/jni/armeabi-v7a/libvosk.so
+0
-0
A
android/app/src/j/jni/x86/libvosk.so
+0
-0
A
android/app/src/j/jni/x86_64/libvosk.so
+0
-0
M
android/app/src/main/java/fr/ebii/card2vcf/audio/AudioNoteRecorder.kt
+6
-10
@@ -12,8 +12,8 @@ data class ResultatEnregistrement(val chemin: String, val dureeMsec: Long)
| 12 | 12 | /** |
| 13 | 13 | * Enregistre un fichier WAV (PCM 16 kHz mono 16 bits) via [AudioRecord]. |
| 14 | 14 | * |
| 15 | - * Chaque buffer PCM capturé est aussi transmis via [onPcm] pour alimenter | |
| 16 | - * [TranscripteurVosk] en streaming pendant l'enregistrement. | |
| 15 | + * La transcription n'a lieu qu'après l'arrêt, sur le fichier produit : la faire ici | |
| 16 | + * ralentirait la boucle de lecture au point de perdre des échantillons. | |
| 17 | 17 | * |
| 18 | 18 | * Durée max : 10 minutes (arrêt automatique). |
| 19 | 19 | * |
@@ -37,16 +37,13 @@ class AudioNoteRecorder : EnregistreurAudio {
| 37 | 37 | @Volatile private var dernierResultat: ResultatEnregistrement? = null |
| 38 | 38 | private var threadEnregistrement: Thread? = null |
| 39 | 39 | |
| 40 | - /** | |
| 41 | - * Démarre l'enregistrement vers [fichierCible]. | |
| 42 | - * [onPcm] est appelé sur le thread d'enregistrement à chaque buffer capturé. | |
| 43 | - */ | |
| 44 | - override fun demarrer(fichierCible: File, onPcm: (ShortArray, Int) -> Unit) { | |
| 40 | + /** Démarre l'enregistrement vers [fichierCible] sur un thread dédié. */ | |
| 41 | + override fun demarrer(fichierCible: File) { | |
| 45 | 42 | check(!enCours) { "Enregistrement déjà en cours" } |
| 46 | 43 | dernierResultat = null |
| 47 | 44 | enCours = true |
| 48 | 45 | threadEnregistrement = Thread( |
| 49 | - { executer(fichierCible, onPcm) }, | |
| 46 | + { executer(fichierCible) }, | |
| 50 | 47 | "AudioNoteRecorder", |
| 51 | 48 | ).also { it.start() } |
| 52 | 49 | } |
@@ -62,7 +59,7 @@ class AudioNoteRecorder : EnregistreurAudio {
| 62 | 59 | return dernierResultat |
| 63 | 60 | } |
| 64 | 61 | |
| 65 | - private fun executer(fichierCible: File, onPcm: (ShortArray, Int) -> Unit) { | |
| 62 | + private fun executer(fichierCible: File) { | |
| 66 | 63 | val tailleBuffer = AudioRecord.getMinBufferSize(FREQUENCE, CANAL, FORMAT) |
| 67 | 64 | .coerceAtLeast(FREQUENCE * 2) // >= 0,5 s de tampon |
| 68 | 65 | val record = AudioRecord( |
@@ -81,7 +78,6 @@ class AudioNoteRecorder : EnregistreurAudio {
| 81 | 78 | val lu = record.read(buffer, 0, buffer.size) |
| 82 | 79 | if (lu > 0) { |
| 83 | 80 | ecriture.ecrireEchantillons(buffer, lu) |
| 84 | - onPcm(buffer, lu) | |
| 85 | 81 | } |
| 86 | 82 | } |
| 87 | 83 | } catch (e: Exception) { |
M
android/app/src/main/java/fr/ebii/card2vcf/audio/EnregistreurAudio.kt
+2
-2
@@ -11,8 +11,8 @@ import java.io.File
| 11 | 11 | * indéfiniment la fin d'un enregistrement qui n'a jamais démarré. |
| 12 | 12 | */ |
| 13 | 13 | interface EnregistreurAudio { |
| 14 | - /** Lance l'enregistrement vers [fichierCible] ; [onPcm] reçoit les échantillons lus. */ | |
| 15 | - fun demarrer(fichierCible: File, onPcm: (ShortArray, Int) -> Unit) | |
| 14 | + /** Lance l'enregistrement vers [fichierCible]. */ | |
| 15 | + fun demarrer(fichierCible: File) | |
| 16 | 16 | |
| 17 | 17 | /** Stoppe l'enregistrement et retourne le fichier produit, ou `null` si rien n'a été capté. */ |
| 18 | 18 | fun arreter(): ResultatEnregistrement? |
A
android/app/src/main/java/fr/ebii/card2vcf/audio/LecteurWav.kt
+50
-0
@@ -0,0 +1,50 @@
| 1 | +package fr.ebii.card2vcf.audio | |
| 2 | + | |
| 3 | +import java.io.Closeable | |
| 4 | +import java.io.DataInputStream | |
| 5 | +import java.io.File | |
| 6 | +import java.nio.ByteBuffer | |
| 7 | +import java.nio.ByteOrder | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * Relit par blocs un WAV PCM 16 bits mono produit par [EcritureWav]. | |
| 11 | + * | |
| 12 | + * Pendant de [EcritureWav] et, comme elle, en JVM pur sans dépendance Android : | |
| 13 | + * la transcription d'une note déjà enregistrée est ainsi testable sans appareil. | |
| 14 | + */ | |
| 15 | +class LecteurWav(fichier: File) : Closeable { | |
| 16 | + | |
| 17 | + private val flux = DataInputStream(fichier.inputStream().buffered()) | |
| 18 | + | |
| 19 | + /** Nombre d'échantillons PCM du fichier, lu dans l'en-tête. */ | |
| 20 | + val nombreEchantillons: Int | |
| 21 | + | |
| 22 | + init { | |
| 23 | + val entete = ByteArray(44) | |
| 24 | + flux.readFully(entete) | |
| 25 | + val tailleData = ByteBuffer.wrap(entete, 40, 4).order(ByteOrder.LITTLE_ENDIAN).int | |
| 26 | + nombreEchantillons = tailleData / 2 | |
| 27 | + } | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * Parcourt le fichier par blocs d'au plus [tailleBloc] échantillons. | |
| 31 | + * | |
| 32 | + * [bloc] reçoit le tampon (réutilisé d'un appel à l'autre), le nombre d'échantillons | |
| 33 | + * valides, et l'avancement dans `]0, 1]`. | |
| 34 | + */ | |
| 35 | + fun parBlocs(tailleBloc: Int, bloc: (ShortArray, Int, Float) -> Unit) { | |
| 36 | + val tampon = ShortArray(tailleBloc) | |
| 37 | + val octets = ByteArray(tailleBloc * 2) | |
| 38 | + var lus = 0 | |
| 39 | + while (lus < nombreEchantillons) { | |
| 40 | + val n = minOf(tailleBloc, nombreEchantillons - lus) | |
| 41 | + flux.readFully(octets, 0, n * 2) | |
| 42 | + val bb = ByteBuffer.wrap(octets, 0, n * 2).order(ByteOrder.LITTLE_ENDIAN) | |
| 43 | + for (i in 0 until n) tampon[i] = bb.short | |
| 44 | + lus += n | |
| 45 | + bloc(tampon, n, lus.toFloat() / nombreEchantillons) | |
| 46 | + } | |
| 47 | + } | |
| 48 | + | |
| 49 | + override fun close() = flux.close() | |
| 50 | +} |
M
android/app/src/main/java/fr/ebii/card2vcf/audio/TranscripteurLocal.kt
+13
-11
@@ -1,5 +1,7 @@
| 1 | 1 | package fr.ebii.card2vcf.audio |
| 2 | 2 | |
| 3 | +import java.io.File | |
| 4 | + | |
| 3 | 5 | /** |
| 4 | 6 | * Interface de transcription locale (ASR sur l'appareil). |
| 5 | 7 | * |
@@ -14,19 +16,19 @@ interface TranscripteurLocal {
| 14 | 16 | val etat: Etat |
| 15 | 17 | |
| 16 | 18 | /** |
| 17 | - * Alimente le moteur avec un buffer PCM capturé par [AudioNoteRecorder]. | |
| 18 | - * Appelé sur le thread d'enregistrement. | |
| 19 | + * Transcrit un WAV déjà enregistré, une fois la capture terminée. | |
| 19 | 20 | * |
| 20 | - * @return Un résultat partiel si disponible, null sinon. | |
| 21 | - */ | |
| 22 | - fun accepterEchantillons(data: ShortArray, longueur: Int): String? | |
| 23 | - | |
| 24 | - /** | |
| 25 | - * Demande le résultat final après la fin de l'enregistrement. | |
| 26 | - * @return Le texte transcrit (peut être vide). | |
| 21 | + * Transcrire après coup plutôt qu'en flux pendant la capture répond à deux défauts : | |
| 22 | + * le moteur travaille par énoncés et perdait tout sauf le dernier, et il tournait sur le | |
| 23 | + * thread de capture, où sa lenteur pouvait affamer `AudioRecord` et trouer le WAV. | |
| 24 | + * | |
| 25 | + * Appel bloquant, à faire hors du thread principal. | |
| 26 | + * | |
| 27 | + * @param onProgression avancement dans `]0, 1]`, pour alimenter la barre de progression. | |
| 28 | + * @return Le texte complet, tous énoncés concaténés (peut être vide). | |
| 27 | 29 | */ |
| 28 | - fun finaliser(): String | |
| 30 | + fun transcrireFichier(fichier: File, onProgression: (Float) -> Unit): String | |
| 29 | 31 | |
| 30 | - /** Réinitialise l'état interne pour une nouvelle session. */ | |
| 32 | + /** Libère le moteur et son modèle. */ | |
| 31 | 33 | fun reinitialiser() |
| 32 | 34 | } |
M
android/app/src/main/java/fr/ebii/card2vcf/audio/TranscripteurVosk.kt
+26
-21
@@ -12,7 +12,7 @@ import java.io.File
| 12 | 12 | /** |
| 13 | 13 | * Transcription locale via le moteur Vosk (modèle français small ~41 Mo). |
| 14 | 14 | * |
| 15 | - * Sur le premier appel à [accepterEchantillons], le modèle est extrait des assets | |
| 15 | + * Sur le premier appel à [transcrireFichier], le modèle est extrait des assets | |
| 16 | 16 | * vers [Context.filesDir] si ce n'est pas déjà fait. |
| 17 | 17 | * |
| 18 | 18 | * Si le modèle n'est ni dans les assets ni dans `filesDir` (saveur `fdroid` sans |
@@ -27,17 +27,10 @@ class TranscripteurVosk(private val context: Context) : TranscripteurLocal {
| 27 | 27 | private const val NOM_MODELE = "vosk-model-small-fr-0.22" |
| 28 | 28 | private const val FREQUENCE = 16_000f |
| 29 | 29 | |
| 30 | - private val json = Json { ignoreUnknownKeys = true } | |
| 30 | + /** 0,5 s d'audio par bloc : compromis entre granularité de la barre et surcoût d'appels. */ | |
| 31 | + private const val TAILLE_BLOC = 8_000 | |
| 31 | 32 | |
| 32 | - /** | |
| 33 | - * Extrait la valeur de la clé "partial" du JSON Vosk. | |
| 34 | - * Retourne null si le texte est vide ou le JSON invalide. | |
| 35 | - */ | |
| 36 | - fun parsagePartiel(jsonStr: String): String? = runCatching { | |
| 37 | - (json.parseToJsonElement(jsonStr).jsonObject["partial"] as? JsonPrimitive) | |
| 38 | - ?.content | |
| 39 | - ?.takeIf { it.isNotEmpty() } | |
| 40 | - }.getOrNull() | |
| 33 | + private val json = Json { ignoreUnknownKeys = true } | |
| 41 | 34 | |
| 42 | 35 | /** |
| 43 | 36 | * Extrait la valeur de la clé "text" du JSON Vosk. |
@@ -111,21 +104,33 @@ class TranscripteurVosk(private val context: Context) : TranscripteurLocal {
| 111 | 104 | } |
| 112 | 105 | } |
| 113 | 106 | |
| 114 | - override fun accepterEchantillons(data: ShortArray, longueur: Int): String? { | |
| 115 | - val rec = obtenirReconnaisseur() ?: return null | |
| 116 | - val octets = shortArrayVersOctets(data, longueur) | |
| 117 | - val complet = rec.acceptWaveForm(octets, octets.size) | |
| 118 | - return if (complet) parsageTexte(rec.result) else parsagePartiel(rec.partialResult) | |
| 119 | - } | |
| 120 | - | |
| 121 | - override fun finaliser(): String { | |
| 122 | - val rec = reconnaisseur ?: return "" | |
| 123 | - return parsageTexte(rec.finalResult) | |
| 107 | + override fun transcrireFichier(fichier: File, onProgression: (Float) -> Unit): String { | |
| 108 | + val rec = obtenirReconnaisseur() ?: return "" | |
| 109 | + return runCatching { | |
| 110 | + LecteurWav(fichier).use { lecteur -> | |
| 111 | + transcrireFlux( | |
| 112 | + lecteur = lecteur, | |
| 113 | + tailleBloc = TAILLE_BLOC, | |
| 114 | + accepterBloc = { bloc, longueur -> | |
| 115 | + val octets = shortArrayVersOctets(bloc, longueur) | |
| 116 | + // true = Vosk vient de clore un énoncé ; son texte doit être conservé, | |
| 117 | + // le reconnaisseur repart de zéro pour le suivant. | |
| 118 | + if (rec.acceptWaveForm(octets, octets.size)) parsageTexte(rec.result) else null | |
| 119 | + }, | |
| 120 | + texteFinal = { parsageTexte(rec.finalResult) }, | |
| 121 | + onProgression = onProgression, | |
| 122 | + ) | |
| 123 | + } | |
| 124 | + }.onFailure { e -> | |
| 125 | + Log.e(TAG, "Échec de la transcription de ${fichier.name}", e) | |
| 126 | + }.getOrDefault("") | |
| 124 | 127 | } |
| 125 | 128 | |
| 126 | 129 | override fun reinitialiser() { |
| 127 | 130 | reconnaisseur?.close() |
| 128 | 131 | reconnaisseur = null |
| 132 | + modele?.close() | |
| 133 | + modele = null | |
| 129 | 134 | } |
| 130 | 135 | |
| 131 | 136 | /** Convertit un tableau de Short PCM en ByteArray little-endian. */ |
A
android/app/src/main/java/fr/ebii/card2vcf/audio/TranscriptionFlux.kt
+33
-0
@@ -0,0 +1,33 @@
| 1 | +package fr.ebii.card2vcf.audio | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Transcrit un WAV déjà enregistré en accumulant **tous** les énoncés. | |
| 5 | + * | |
| 6 | + * Vosk travaille par énoncés : il en clôt un à chaque silence, en livre le texte, puis | |
| 7 | + * repart de zéro. Chaque énoncé clos doit donc être conservé — sinon seul le dernier | |
| 8 | + * subsiste, et on n'obtient que la fin de la note. | |
| 9 | + * | |
| 10 | + * Extraite de [TranscripteurVosk] et paramétrée par [accepterBloc] / [texteFinal] pour | |
| 11 | + * rester testable en JVM pur, sans la bibliothèque native. | |
| 12 | + * | |
| 13 | + * @param accepterBloc reçoit un bloc PCM ; renvoie le texte de l'énoncé qu'il vient de | |
| 14 | + * clore, ou `null` si l'énoncé se poursuit. | |
| 15 | + * @param texteFinal texte de l'énoncé resté ouvert à la fin du fichier. | |
| 16 | + */ | |
| 17 | +fun transcrireFlux( | |
| 18 | + lecteur: LecteurWav, | |
| 19 | + tailleBloc: Int, | |
| 20 | + accepterBloc: (ShortArray, Int) -> String?, | |
| 21 | + texteFinal: () -> String, | |
| 22 | + onProgression: (Float) -> Unit, | |
| 23 | +): String { | |
| 24 | + val segments = mutableListOf<String>() | |
| 25 | + lecteur.parBlocs(tailleBloc) { bloc, longueur, avancement -> | |
| 26 | + accepterBloc(bloc, longueur)?.takeIf { it.isNotBlank() }?.let { segments.add(it.trim()) } | |
| 27 | + onProgression(avancement) | |
| 28 | + } | |
| 29 | + if (lecteur.nombreEchantillons > 0) { | |
| 30 | + texteFinal().takeIf { it.isNotBlank() }?.let { segments.add(it.trim()) } | |
| 31 | + } | |
| 32 | + return segments.joinToString(" ") | |
| 33 | +} |
M
android/app/src/main/java/fr/ebii/card2vcf/ui/audio/EnregistrementNoteSheet.kt
+67
-36
@@ -1,6 +1,7 @@
| 1 | 1 | package fr.ebii.card2vcf.ui.audio |
| 2 | 2 | |
| 3 | 3 | import android.Manifest |
| 4 | +import android.content.Context | |
| 4 | 5 | import android.content.pm.PackageManager |
| 5 | 6 | import android.media.MediaPlayer |
| 6 | 7 | import androidx.activity.compose.rememberLauncherForActivityResult |
@@ -24,6 +25,7 @@ import androidx.compose.material3.CircularProgressIndicator
| 24 | 25 | import androidx.compose.material3.ExperimentalMaterial3Api |
| 25 | 26 | import androidx.compose.material3.Icon |
| 26 | 27 | import androidx.compose.material3.IconButton |
| 28 | +import androidx.compose.material3.LinearProgressIndicator | |
| 27 | 29 | import androidx.compose.material3.MaterialTheme |
| 28 | 30 | import androidx.compose.material3.ModalBottomSheet |
| 29 | 31 | import androidx.compose.material3.OutlinedButton |
@@ -46,6 +48,7 @@ import androidx.core.content.ContextCompat
| 46 | 48 | import fr.ebii.card2vcf.R |
| 47 | 49 | import fr.ebii.card2vcf.audio.AudioNoteRecorder |
| 48 | 50 | import fr.ebii.card2vcf.audio.EnregistreurAudio |
| 51 | +import fr.ebii.card2vcf.audio.TranscripteurLocal | |
| 49 | 52 | import fr.ebii.card2vcf.audio.TranscripteurVosk |
| 50 | 53 | import fr.ebii.card2vcf.ui.composants.ChampTexte |
| 51 | 54 | import fr.ebii.card2vcf.ui.theme.Bordure |
@@ -57,6 +60,7 @@ import kotlinx.coroutines.delay
| 57 | 60 | import kotlinx.coroutines.launch |
| 58 | 61 | import kotlinx.coroutines.withContext |
| 59 | 62 | import java.io.File |
| 63 | +import kotlin.math.roundToInt | |
| 60 | 64 | |
| 61 | 65 | /** Formate une durée en ms en "mm:ss". */ |
| 62 | 66 | fun formaterDuree(ms: Long): String { |
@@ -66,7 +70,7 @@ fun formaterDuree(ms: Long): String {
| 66 | 70 | return "%02d:%02d".format(min, sec) |
| 67 | 71 | } |
| 68 | 72 | |
| 69 | -private enum class Phase { EN_ATTENTE_PERMISSION, EN_COURS, ARRET, EDITION } | |
| 73 | +private enum class Phase { EN_ATTENTE_PERMISSION, EN_COURS, TRANSCRIPTION, EDITION } | |
| 70 | 74 | |
| 71 | 75 | /** |
| 72 | 76 | * Feuille d'enregistrement modale commune (contact et projet). |
@@ -92,12 +96,16 @@ fun EnregistrementNoteSheet(
| 92 | 96 | * « enregistrement en cours ». |
| 93 | 97 | */ |
| 94 | 98 | enregistreurFactory: () -> EnregistreurAudio = { AudioNoteRecorder() }, |
| 99 | + /** Fabrique du transcripteur. Injectable pour les mêmes raisons que [enregistreurFactory]. */ | |
| 100 | + transcripteurFactory: (Context) -> TranscripteurLocal = { TranscripteurVosk(it) }, | |
| 95 | 101 | ) { |
| 96 | 102 | val context = LocalContext.current |
| 97 | 103 | val modeLocal = !modeServeur && voskDisponible |
| 98 | 104 | |
| 99 | 105 | val recorder = remember { enregistreurFactory() } |
| 100 | - val transcripteur = remember { if (modeLocal) TranscripteurVosk(context.applicationContext) else null } | |
| 106 | + val transcripteur = remember { | |
| 107 | + if (modeLocal) transcripteurFactory(context.applicationContext) else null | |
| 108 | + } | |
| 101 | 109 | |
| 102 | 110 | var micAccorde by remember { |
| 103 | 111 | mutableStateOf( |
@@ -110,7 +118,7 @@ fun EnregistrementNoteSheet(
| 110 | 118 | |
| 111 | 119 | var phase by remember { mutableStateOf(if (micAccorde) Phase.EN_COURS else Phase.EN_ATTENTE_PERMISSION) } |
| 112 | 120 | var dureeMs by remember { mutableStateOf(0L) } |
| 113 | - var textePartiel by remember { mutableStateOf("") } | |
| 121 | + var progressionTranscription by remember { mutableStateOf(0f) } | |
| 114 | 122 | var texteTranscrit by remember { mutableStateOf("") } |
| 115 | 123 | var sujet by remember { mutableStateOf("") } |
| 116 | 124 | var audioPath by remember { mutableStateOf<String?>(null) } |
@@ -138,10 +146,7 @@ fun EnregistrementNoteSheet(
| 138 | 146 | File.createTempFile("note_vocale_", ".wav", dir) |
| 139 | 147 | } |
| 140 | 148 | audioPath = file.absolutePath |
| 141 | - recorder.demarrer(file) { data, len -> | |
| 142 | - val partial = transcripteur?.accepterEchantillons(data, len) | |
| 143 | - if (partial != null) scope.launch(Dispatchers.Main.immediate) { textePartiel = partial } | |
| 144 | - } | |
| 149 | + recorder.demarrer(file) | |
| 145 | 150 | while (phase == Phase.EN_COURS) { |
| 146 | 151 | dureeMs = System.currentTimeMillis() - startMs |
| 147 | 152 | delay(100L) |
@@ -183,27 +188,30 @@ fun EnregistrementNoteSheet(
| 183 | 188 | ) |
| 184 | 189 | phase == Phase.EN_COURS -> EnCoursContent( |
| 185 | 190 | dureeMs = dureeMs, |
| 186 | - textePartiel = textePartiel, | |
| 187 | 191 | modeLocal = modeLocal, |
| 188 | 192 | onStop = { |
| 189 | 193 | scope.launch { |
| 190 | - phase = Phase.ARRET | |
| 194 | + phase = Phase.TRANSCRIPTION | |
| 195 | + progressionTranscription = 0f | |
| 191 | 196 | val resultat = withContext(Dispatchers.IO) { recorder.arreter() } |
| 192 | - val texteFinal = if (modeLocal) { | |
| 193 | - withContext(Dispatchers.IO) { transcripteur?.finaliser().orEmpty() } | |
| 197 | + audioPath = resultat?.chemin | |
| 198 | + texteTranscrit = if (modeLocal && resultat != null) { | |
| 199 | + withContext(Dispatchers.IO) { | |
| 200 | + transcripteur?.transcrireFichier(File(resultat.chemin)) { avancement -> | |
| 201 | + scope.launch(Dispatchers.Main.immediate) { | |
| 202 | + progressionTranscription = avancement | |
| 203 | + } | |
| 204 | + }.orEmpty() | |
| 205 | + } | |
| 194 | 206 | } else { |
| 195 | 207 | "" |
| 196 | 208 | } |
| 197 | - texteTranscrit = texteFinal.ifBlank { textePartiel } | |
| 198 | - audioPath = resultat?.chemin | |
| 199 | 209 | sujet = genererSujetParDefaut(formatSujetDefaut) |
| 200 | 210 | phase = Phase.EDITION |
| 201 | 211 | } |
| 202 | 212 | }, |
| 203 | 213 | ) |
| 204 | - phase == Phase.ARRET -> Box(Modifier.fillMaxWidth(), contentAlignment = Alignment.Center) { | |
| 205 | - CircularProgressIndicator(color = MaterialTheme.colorScheme.secondary) | |
| 206 | - } | |
| 214 | + phase == Phase.TRANSCRIPTION -> TranscriptionContent(progressionTranscription) | |
| 207 | 215 | phase == Phase.EDITION -> EditionContent( |
| 208 | 216 | sujet = sujet, |
| 209 | 217 | texteTranscrit = texteTranscrit, |
@@ -246,7 +254,6 @@ private fun PermissionContent(onDemander: () -> Unit) {
| 246 | 254 | @Composable |
| 247 | 255 | private fun EnCoursContent( |
| 248 | 256 | dureeMs: Long, |
| 249 | - textePartiel: String, | |
| 250 | 257 | modeLocal: Boolean, |
| 251 | 258 | onStop: () -> Unit, |
| 252 | 259 | ) { |
@@ -263,25 +270,17 @@ private fun EnCoursContent(
| 263 | 270 | color = Ink, |
| 264 | 271 | ) |
| 265 | 272 | } |
| 266 | - if (modeLocal && textePartiel.isNotBlank()) { | |
| 267 | - Text( | |
| 268 | - textePartiel, | |
| 269 | - style = MaterialTheme.typography.bodyMedium, | |
| 270 | - color = TexteFaible, | |
| 271 | - ) | |
| 272 | - } else if (!modeLocal) { | |
| 273 | - Text( | |
| 274 | - stringResource(R.string.note_vocale_transcription_serveur), | |
| 275 | - style = MaterialTheme.typography.bodySmall, | |
| 276 | - color = TexteFaible, | |
| 277 | - ) | |
| 278 | - } else { | |
| 279 | - Text( | |
| 280 | - stringResource(R.string.note_vocale_transcription_en_cours), | |
| 281 | - style = MaterialTheme.typography.bodySmall, | |
| 282 | - color = TexteFaible, | |
| 283 | - ) | |
| 284 | - } | |
| 273 | + Text( | |
| 274 | + stringResource( | |
| 275 | + if (modeLocal) { | |
| 276 | + R.string.note_vocale_transcription_apres_arret | |
| 277 | + } else { | |
| 278 | + R.string.note_vocale_transcription_serveur | |
| 279 | + }, | |
| 280 | + ), | |
| 281 | + style = MaterialTheme.typography.bodySmall, | |
| 282 | + color = TexteFaible, | |
| 283 | + ) | |
| 285 | 284 | Button(onClick = onStop, modifier = Modifier.fillMaxWidth()) { |
| 286 | 285 | Icon(Icons.Filled.Stop, contentDescription = null) |
| 287 | 286 | Spacer(Modifier.size(8.dp)) |
@@ -436,3 +435,35 @@ fun LecteurAudio(
| 436 | 435 | } |
| 437 | 436 | } |
| 438 | 437 | } |
| 438 | + | |
| 439 | +/** | |
| 440 | + * Phase de transcription hors ligne : le WAV est déjà enregistré, Vosk le relit. | |
| 441 | + * | |
| 442 | + * La barre est déterminée — une note longue peut demander plusieurs dizaines de secondes | |
| 443 | + * sur un appareil modeste, et un indicateur tournant sans fin laisserait croire à un blocage. | |
| 444 | + */ | |
| 445 | +@Composable | |
| 446 | +internal fun TranscriptionContent(progression: Float) { | |
| 447 | + val borne = progression.coerceIn(0f, 1f) | |
| 448 | + Column( | |
| 449 | + Modifier.fillMaxWidth(), | |
| 450 | + horizontalAlignment = Alignment.CenterHorizontally, | |
| 451 | + verticalArrangement = Arrangement.spacedBy(12.dp), | |
| 452 | + ) { | |
| 453 | + Text( | |
| 454 | + stringResource(R.string.note_vocale_transcription_en_cours), | |
| 455 | + color = Ink, | |
| 456 | + style = MaterialTheme.typography.bodyMedium, | |
| 457 | + ) | |
| 458 | + LinearProgressIndicator( | |
| 459 | + progress = { borne }, | |
| 460 | + modifier = Modifier.fillMaxWidth(), | |
| 461 | + color = MaterialTheme.colorScheme.secondary, | |
| 462 | + ) | |
| 463 | + Text( | |
| 464 | + stringResource(R.string.note_vocale_transcription_pourcent, (borne * 100).roundToInt()), | |
| 465 | + color = TexteFaible, | |
| 466 | + style = MaterialTheme.typography.bodySmall, | |
| 467 | + ) | |
| 468 | + } | |
| 469 | +} |
M
android/app/src/main/res/values-en/strings.xml
+2
-0
@@ -161,6 +161,8 @@
| 161 | 161 | <string name="note_vocale_stop">Stop recording</string> |
| 162 | 162 | <string name="note_vocale_transcription_en_cours">Transcription in progress…</string> |
| 163 | 163 | <string name="note_vocale_transcription_serveur">Server transcription after sync</string> |
| 164 | + <string name="note_vocale_transcription_pourcent">%1$d %%</string> | |
| 165 | + <string name="note_vocale_transcription_apres_arret">Transcribed when you stop recording</string> | |
| 164 | 166 | <string name="note_vocale_sujet_label">Note subject</string> |
| 165 | 167 | <string name="note_vocale_texte_label">Transcription</string> |
| 166 | 168 | <string name="note_vocale_sauvegarder">Save</string> |
M
android/app/src/main/res/values/strings.xml
+2
-0
@@ -165,6 +165,8 @@
| 165 | 165 | <string name="note_vocale_stop">Arrêter l\'enregistrement</string> |
| 166 | 166 | <string name="note_vocale_transcription_en_cours">Transcription en cours…</string> |
| 167 | 167 | <string name="note_vocale_transcription_serveur">Transcription serveur après synchronisation</string> |
| 168 | + <string name="note_vocale_transcription_pourcent">%1$d %%</string> | |
| 169 | + <string name="note_vocale_transcription_apres_arret">Transcription à l\'arrêt de l\'enregistrement</string> | |
| 168 | 170 | <string name="note_vocale_sujet_label">Sujet de la note</string> |
| 169 | 171 | <string name="note_vocale_texte_label">Transcription</string> |
| 170 | 172 | <string name="note_vocale_sauvegarder">Sauvegarder</string> |
A
android/app/src/test/java/fr/ebii/card2vcf/audio/LecteurWavTest.kt
+85
-0
@@ -0,0 +1,85 @@
| 1 | +package fr.ebii.card2vcf.audio | |
| 2 | + | |
| 3 | +import java.io.File | |
| 4 | +import kotlin.test.Test | |
| 5 | +import kotlin.test.assertEquals | |
| 6 | +import kotlin.test.assertTrue | |
| 7 | + | |
| 8 | +/** Tests JVM purs : relit ce que [EcritureWav] a produit. */ | |
| 9 | +class LecteurWavTest { | |
| 10 | + | |
| 11 | + /** Écrit un WAV de [nombre] échantillons (rampe déterministe) et le retourne. */ | |
| 12 | + private fun wavDeTest(nombre: Int): File { | |
| 13 | + val f = File.createTempFile("lecteur_wav_", ".wav").also { it.deleteOnExit() } | |
| 14 | + val ecriture = EcritureWav(f) | |
| 15 | + val bloc = ShortArray(100) | |
| 16 | + var ecrits = 0 | |
| 17 | + while (ecrits < nombre) { | |
| 18 | + val n = minOf(bloc.size, nombre - ecrits) | |
| 19 | + for (i in 0 until n) bloc[i] = (ecrits + i).toShort() | |
| 20 | + ecriture.ecrireEchantillons(bloc, n) | |
| 21 | + ecrits += n | |
| 22 | + } | |
| 23 | + ecriture.fermer() | |
| 24 | + return f | |
| 25 | + } | |
| 26 | + | |
| 27 | + @Test | |
| 28 | + fun relitTousLesEchantillonsEcrits() { | |
| 29 | + val fichier = wavDeTest(1_000) | |
| 30 | + val lus = mutableListOf<Short>() | |
| 31 | + | |
| 32 | + LecteurWav(fichier).use { lecteur -> | |
| 33 | + lecteur.parBlocs(256) { bloc, longueur, _ -> | |
| 34 | + for (i in 0 until longueur) lus.add(bloc[i]) | |
| 35 | + } | |
| 36 | + } | |
| 37 | + | |
| 38 | + assertEquals(1_000, lus.size) | |
| 39 | + assertEquals(List(1_000) { it.toShort() }, lus) | |
| 40 | + } | |
| 41 | + | |
| 42 | + @Test | |
| 43 | + fun exposeLeNombreDEchantillons() { | |
| 44 | + LecteurWav(wavDeTest(777)).use { assertEquals(777, it.nombreEchantillons) } | |
| 45 | + } | |
| 46 | + | |
| 47 | + @Test | |
| 48 | + fun progressionCroitDeZeroAUn() { | |
| 49 | + val progressions = mutableListOf<Float>() | |
| 50 | + | |
| 51 | + LecteurWav(wavDeTest(1_000)).use { lecteur -> | |
| 52 | + lecteur.parBlocs(256) { _, _, avancement -> progressions += avancement } | |
| 53 | + } | |
| 54 | + | |
| 55 | + assertEquals(4, progressions.size) | |
| 56 | + assertEquals(1f, progressions.last()) | |
| 57 | + assertTrue(progressions.zipWithNext().all { it.first < it.second }, "progression non croissante : $progressions") | |
| 58 | + assertTrue(progressions.all { it > 0f && it <= 1f }, "progression hors bornes : $progressions") | |
| 59 | + } | |
| 60 | + | |
| 61 | + @Test | |
| 62 | + fun fichierSansDonneesNAppellePasLeBloc() { | |
| 63 | + val f = File.createTempFile("vide_", ".wav").also { it.deleteOnExit() } | |
| 64 | + EcritureWav(f).fermer() | |
| 65 | + var appels = 0 | |
| 66 | + | |
| 67 | + LecteurWav(f).use { lecteur -> | |
| 68 | + assertEquals(0, lecteur.nombreEchantillons) | |
| 69 | + lecteur.parBlocs(256) { _, _, _ -> appels++ } | |
| 70 | + } | |
| 71 | + | |
| 72 | + assertEquals(0, appels) | |
| 73 | + } | |
| 74 | + | |
| 75 | + @Test | |
| 76 | + fun dernierBlocPartielRenvoieLaLongueurReelle() { | |
| 77 | + val longueurs = mutableListOf<Int>() | |
| 78 | + | |
| 79 | + LecteurWav(wavDeTest(300)).use { lecteur -> | |
| 80 | + lecteur.parBlocs(256) { _, longueur, _ -> longueurs += longueur } | |
| 81 | + } | |
| 82 | + | |
| 83 | + assertEquals(listOf(256, 44), longueurs) | |
| 84 | + } | |
| 85 | +} |
M
android/app/src/test/java/fr/ebii/card2vcf/audio/TranscripteurLocalFake.kt
+10
-10
@@ -1,27 +1,27 @@
| 1 | 1 | package fr.ebii.card2vcf.audio |
| 2 | 2 | |
| 3 | +import java.io.File | |
| 4 | + | |
| 3 | 5 | /** |
| 4 | 6 | * Implémentation factice de [TranscripteurLocal] pour les tests unitaires. |
| 5 | 7 | */ |
| 6 | -class TranscripteurLocalFake(disponible: Boolean = true) : TranscripteurLocal { | |
| 8 | +class TranscripteurLocalFake( | |
| 9 | + disponible: Boolean = true, | |
| 10 | + private val texte: String = "transcription simulée", | |
| 11 | +) : TranscripteurLocal { | |
| 7 | 12 | |
| 8 | 13 | override val etat: TranscripteurLocal.Etat = |
| 9 | 14 | if (disponible) TranscripteurLocal.Etat.DISPONIBLE else TranscripteurLocal.Etat.INDISPONIBLE |
| 10 | 15 | |
| 11 | - private val buffersRecus = mutableListOf<Pair<ShortArray, Int>>() | |
| 12 | 16 | var reinitialiseAppele = false |
| 17 | + val progressionsEmises = mutableListOf<Float>() | |
| 13 | 18 | |
| 14 | - override fun accepterEchantillons(data: ShortArray, longueur: Int): String? { | |
| 15 | - buffersRecus += data to longueur | |
| 16 | - return null // pas de résultat partiel simulé | |
| 19 | + override fun transcrireFichier(fichier: File, onProgression: (Float) -> Unit): String { | |
| 20 | + listOf(0.5f, 1f).forEach { onProgression(it); progressionsEmises.add(it) } | |
| 21 | + return texte | |
| 17 | 22 | } |
| 18 | 23 | |
| 19 | - override fun finaliser(): String = "transcription simulée" | |
| 20 | - | |
| 21 | 24 | override fun reinitialiser() { |
| 22 | 25 | reinitialiseAppele = true |
| 23 | - buffersRecus.clear() | |
| 24 | 26 | } |
| 25 | - | |
| 26 | - fun nombreBuffersRecus(): Int = buffersRecus.size | |
| 27 | 27 | } |
M
android/app/src/test/java/fr/ebii/card2vcf/audio/TranscripteurVoskTest.kt
+2
-44
@@ -2,42 +2,16 @@ package fr.ebii.card2vcf.audio
| 2 | 2 | |
| 3 | 3 | import kotlin.test.Test |
| 4 | 4 | import kotlin.test.assertEquals |
| 5 | -import kotlin.test.assertNull | |
| 6 | 5 | import kotlin.test.assertTrue |
| 7 | 6 | |
| 8 | 7 | /** |
| 9 | 8 | * Tests JVM des méthodes de parsing JSON de Vosk et du fake. |
| 10 | 9 | * N'instancie pas TranscripteurVosk (nécessite un Context Android + lib native). |
| 10 | + * | |
| 11 | + * L'assemblage des énoncés, lui, est couvert par [TranscriptionFluxTest]. | |
| 11 | 12 | */ |
| 12 | 13 | class TranscripteurVoskTest { |
| 13 | 14 | |
| 14 | - // --- Parsing "partial" --- | |
| 15 | - | |
| 16 | - @Test | |
| 17 | - fun parsagePartielNormal() { | |
| 18 | - val json = """{"partial":"bonjour le"}""" | |
| 19 | - assertEquals("bonjour le", TranscripteurVosk.parsagePartiel(json)) | |
| 20 | - } | |
| 21 | - | |
| 22 | - @Test | |
| 23 | - fun parsagePartielAvecEspaces() { | |
| 24 | - val json = """{ "partial" : "comment allez vous" }""" | |
| 25 | - assertEquals("comment allez vous", TranscripteurVosk.parsagePartiel(json)) | |
| 26 | - } | |
| 27 | - | |
| 28 | - @Test | |
| 29 | - fun parsagePartielVideRetourneNull() { | |
| 30 | - val json = """{"partial":""}""" | |
| 31 | - assertNull(TranscripteurVosk.parsagePartiel(json)) | |
| 32 | - } | |
| 33 | - | |
| 34 | - @Test | |
| 35 | - fun parsagePartielJsonInvalidRetourneNull() { | |
| 36 | - assertNull(TranscripteurVosk.parsagePartiel("not json at all")) | |
| 37 | - assertNull(TranscripteurVosk.parsagePartiel("")) | |
| 38 | - assertNull(TranscripteurVosk.parsagePartiel("{}")) | |
| 39 | - } | |
| 40 | - | |
| 41 | 15 | // --- Parsing "text" (résultat final) --- |
| 42 | 16 | |
| 43 | 17 | @Test |
@@ -80,25 +54,9 @@ class TranscripteurVoskTest {
| 80 | 54 | } |
| 81 | 55 | |
| 82 | 56 | @Test |
| 83 | - fun fakeAccepteEchantillons() { | |
| 84 | - val fake = TranscripteurLocalFake() | |
| 85 | - assertNull(fake.accepterEchantillons(ShortArray(160), 160)) | |
| 86 | - assertNull(fake.accepterEchantillons(ShortArray(160), 160)) | |
| 87 | - assertEquals(2, fake.nombreBuffersRecus()) | |
| 88 | - } | |
| 89 | - | |
| 90 | - @Test | |
| 91 | - fun fakeFinaliserRetourneTexte() { | |
| 92 | - val fake = TranscripteurLocalFake() | |
| 93 | - assertEquals("transcription simulée", fake.finaliser()) | |
| 94 | - } | |
| 95 | - | |
| 96 | - @Test | |
| 97 | 57 | fun fakeReinitialiser() { |
| 98 | 58 | val fake = TranscripteurLocalFake() |
| 99 | - fake.accepterEchantillons(ShortArray(100), 100) | |
| 100 | 59 | fake.reinitialiser() |
| 101 | 60 | assertTrue(fake.reinitialiseAppele) |
| 102 | - assertEquals(0, fake.nombreBuffersRecus()) | |
| 103 | 61 | } |
| 104 | 62 | } |
A
android/app/src/test/java/fr/ebii/card2vcf/audio/TranscriptionFluxTest.kt
+98
-0
@@ -0,0 +1,98 @@
| 1 | +package fr.ebii.card2vcf.audio | |
| 2 | + | |
| 3 | +import java.io.File | |
| 4 | +import kotlin.test.Test | |
| 5 | +import kotlin.test.assertEquals | |
| 6 | +import kotlin.test.assertTrue | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * Tests JVM de la boucle de transcription par énoncés, sans la lib native Vosk. | |
| 10 | + * | |
| 11 | + * Épingle le défaut corrigé : Vosk clôt un énoncé à chaque silence et repart de zéro. | |
| 12 | + * Sans accumulation, seul le dernier énoncé survivait — on n'obtenait que la fin de la note. | |
| 13 | + */ | |
| 14 | +class TranscriptionFluxTest { | |
| 15 | + | |
| 16 | + private fun wav(nombreEchantillons: Int): File { | |
| 17 | + val f = File.createTempFile("flux_", ".wav").also { it.deleteOnExit() } | |
| 18 | + val e = EcritureWav(f) | |
| 19 | + e.ecrireEchantillons(ShortArray(nombreEchantillons), nombreEchantillons) | |
| 20 | + e.fermer() | |
| 21 | + return f | |
| 22 | + } | |
| 23 | + | |
| 24 | + @Test | |
| 25 | + fun concateneTousLesEnoncesPuisLeTexteFinal() { | |
| 26 | + val enonces = listOf("bonjour Luc", "je te rappelle demain", "pour le devis") | |
| 27 | + var appel = 0 | |
| 28 | + | |
| 29 | + val texte = LecteurWav(wav(300)).use { lecteur -> | |
| 30 | + transcrireFlux( | |
| 31 | + lecteur = lecteur, | |
| 32 | + tailleBloc = 100, | |
| 33 | + accepterBloc = { _, _ -> enonces.getOrNull(appel++) }, | |
| 34 | + texteFinal = { "à bientôt" }, | |
| 35 | + onProgression = {}, | |
| 36 | + ) | |
| 37 | + } | |
| 38 | + | |
| 39 | + assertEquals("bonjour Luc je te rappelle demain pour le devis à bientôt", texte) | |
| 40 | + } | |
| 41 | + | |
| 42 | + @Test | |
| 43 | + fun sansEnonceCloseRenvoieLeTexteFinal() { | |
| 44 | + val texte = LecteurWav(wav(300)).use { lecteur -> | |
| 45 | + transcrireFlux(lecteur, 100, { _, _ -> null }, { "tout en un seul énoncé" }, {}) | |
| 46 | + } | |
| 47 | + | |
| 48 | + assertEquals("tout en un seul énoncé", texte) | |
| 49 | + } | |
| 50 | + | |
| 51 | + @Test | |
| 52 | + fun ignoreLesEnoncesVides() { | |
| 53 | + val retours = listOf("premier", "", " ", "dernier") | |
| 54 | + var appel = 0 | |
| 55 | + | |
| 56 | + val texte = LecteurWav(wav(400)).use { lecteur -> | |
| 57 | + transcrireFlux(lecteur, 100, { _, _ -> retours.getOrNull(appel++) }, { "" }, {}) | |
| 58 | + } | |
| 59 | + | |
| 60 | + assertEquals("premier dernier", texte) | |
| 61 | + } | |
| 62 | + | |
| 63 | + @Test | |
| 64 | + fun signaleLaProgressionJusquAUn() { | |
| 65 | + val vues = mutableListOf<Float>() | |
| 66 | + | |
| 67 | + LecteurWav(wav(1_000)).use { lecteur -> | |
| 68 | + transcrireFlux(lecteur, 256, { _, _ -> null }, { "" }, { vues.add(it) }) | |
| 69 | + } | |
| 70 | + | |
| 71 | + assertEquals(4, vues.size) | |
| 72 | + assertEquals(1f, vues.last()) | |
| 73 | + assertTrue(vues.zipWithNext().all { it.first < it.second }, "progression non croissante : $vues") | |
| 74 | + } | |
| 75 | + | |
| 76 | + @Test | |
| 77 | + fun fichierSansDonneesRenvoieLeTexteFinalSeul() { | |
| 78 | + val f = File.createTempFile("vide_flux_", ".wav").also { it.deleteOnExit() } | |
| 79 | + EcritureWav(f).fermer() | |
| 80 | + | |
| 81 | + val texte = LecteurWav(f).use { lecteur -> | |
| 82 | + transcrireFlux(lecteur, 256, { _, _ -> "jamais appelé" }, { "" }, {}) | |
| 83 | + } | |
| 84 | + | |
| 85 | + assertEquals("", texte) | |
| 86 | + } | |
| 87 | + | |
| 88 | + @Test | |
| 89 | + fun transmetLaLongueurReelleDuDernierBloc() { | |
| 90 | + val longueurs = mutableListOf<Int>() | |
| 91 | + | |
| 92 | + LecteurWav(wav(300)).use { lecteur -> | |
| 93 | + transcrireFlux(lecteur, 256, { _, n -> longueurs.add(n); null }, { "" }, {}) | |
| 94 | + } | |
| 95 | + | |
| 96 | + assertEquals(listOf(256, 44), longueurs) | |
| 97 | + } | |
| 98 | +} |
M
android/app/src/test/java/fr/ebii/card2vcf/ui/audio/EnregistrementNoteSheetTest.kt
+33
-1
@@ -158,6 +158,38 @@ class EnregistrementNoteSheetTest {
| 158 | 158 | |
| 159 | 159 | assert(annule) { "onAnnuler doit être appelé au clic du bouton Annuler" } |
| 160 | 160 | } |
| 161 | + | |
| 162 | + /** | |
| 163 | + * Barre de progression de la transcription hors ligne. | |
| 164 | + * | |
| 165 | + * Testée sur le composable seul, comme [EditionContent] : la transition | |
| 166 | + * EN_COURS → TRANSCRIPTION → EDITION n'est pas rejouable sous Robolectric (cf. la limite | |
| 167 | + * documentée plus haut). | |
| 168 | + * | |
| 169 | + * Preuve de rougeur : sans [TranscriptionContent], le test ne compile pas ; avec un | |
| 170 | + * indicateur indéterminé sans pourcentage, `onNodeWithText("42 %")` échoue. | |
| 171 | + */ | |
| 172 | + @Test | |
| 173 | + fun transcription_affiche_le_pourcentage_de_progression() { | |
| 174 | + composeTestRule.setContent { TranscriptionContent(progression = 0.42f) } | |
| 175 | + | |
| 176 | + composeTestRule.onNodeWithText("Transcription en cours…").assertIsDisplayed() | |
| 177 | + composeTestRule.onNodeWithText("42 %").assertIsDisplayed() | |
| 178 | + } | |
| 179 | + | |
| 180 | + @Test | |
| 181 | + fun transcription_affiche_zero_pourcent_au_demarrage() { | |
| 182 | + composeTestRule.setContent { TranscriptionContent(progression = 0f) } | |
| 183 | + | |
| 184 | + composeTestRule.onNodeWithText("0 %").assertIsDisplayed() | |
| 185 | + } | |
| 186 | + | |
| 187 | + @Test | |
| 188 | + fun transcription_affiche_cent_pourcent_a_la_fin() { | |
| 189 | + composeTestRule.setContent { TranscriptionContent(progression = 1f) } | |
| 190 | + | |
| 191 | + composeTestRule.onNodeWithText("100 %").assertIsDisplayed() | |
| 192 | + } | |
| 161 | 193 | } |
| 162 | 194 | |
| 163 | 195 | /** |
@@ -165,7 +197,7 @@ class EnregistrementNoteSheetTest {
| 165 | 197 | * ce qui permet à la feuille de passer en phase d'édition sous Robolectric. |
| 166 | 198 | */ |
| 167 | 199 | private class FauxEnregistreur : EnregistreurAudio { |
| 168 | - override fun demarrer(fichierCible: File, onPcm: (ShortArray, Int) -> Unit) { | |
| 200 | + override fun demarrer(fichierCible: File) { | |
| 169 | 201 | fichierCible.parentFile?.mkdirs() |
| 170 | 202 | fichierCible.writeBytes(ByteArray(0)) |
| 171 | 203 | } |
A
android/app/src/vosk-0.3.47.aar
+0
-0
A
android/app/src/vosk-0.3.70.aar
+0
-0
GitRust