Cotton code
68 lines · 4.1 KB · KotlinRaw
package com.cottondb.voice/** * STAND-INS, until the voice models' catalogue has its files uploaded (kits/shell/voice/models.json: url null today). * sherpa-onnx's own published models, named as stand-ins everywhere they show (ids start `standin-`, the screen says * so): a small streaming English transducer for the live pass, Whisper tiny (multilingual) for the second pass and for * the live pass of a language with no streaming model, read on voice-activity segments (Silero VAD). * * A planned model whose files cannot be fetched (no url or no sha256) and is not already held stands in by language * (Plan.resolve). Delete this file when every planned model has its url. */object StandIns {    private const val HF = "https://huggingface.co/csukuangfj"    /** The catalogue's `levelling` (kits/shell/voice/models.json), for the stand-ins that do not level their own input. */    private val LEVELLING = Levelling(belowPeak = 0.1f, toPeak = 0.5f, maxGain = 100f)    val zipformerEn = ModelEntry(        id = "standin-zipformer-en-20m",        kind = "online-transducer",        role = "live",        languages = listOf("en"),        files = listOf(            ModelFile("encoder-epoch-99-avg-1.int8.onnx", "$HF/sherpa-onnx-streaming-zipformer-en-20M-2023-02-17/resolve/main/encoder-epoch-99-avg-1.int8.onnx", "3810755ce7c3ab26b42a8bcf39d191308fa27fb0f53358823ba46141d03b7eb3", 42845182, part = "encoder"),            ModelFile("decoder-epoch-99-avg-1.int8.onnx", "$HF/sherpa-onnx-streaming-zipformer-en-20M-2023-02-17/resolve/main/decoder-epoch-99-avg-1.int8.onnx", "21e2a2acd961b3ac72f55be2f10f1a285e1b0b0ba010d7c0b6eab141411b163c", 539499, part = "decoder"),            ModelFile("joiner-epoch-99-avg-1.int8.onnx", "$HF/sherpa-onnx-streaming-zipformer-en-20M-2023-02-17/resolve/main/joiner-epoch-99-avg-1.int8.onnx", "e085d73b593cf9b0707f370dbd656d58327d3fe36d80d849202ef81df02cb01e", 259572, part = "joiner"),            ModelFile("tokens.txt", "$HF/sherpa-onnx-streaming-zipformer-en-20M-2023-02-17/resolve/main/tokens.txt", "49e3c2646595fd907228b3c6787069658f67b17377c60aeb8619c4551b2316fb", 5048, part = "tokens"),        ),        upperCase = true,        standIn = true,        // A zipformer does not level its own input: quiet speech reads as silence without the catalogue's levelling.        level = LEVELLING,    )    val whisperTiny = ModelEntry(        id = "standin-whisper-tiny",        kind = "offline-whisper",        role = "both",        languages = listOf("*"),        files = listOf(            ModelFile("tiny-encoder.int8.onnx", "$HF/sherpa-onnx-whisper-tiny/resolve/main/tiny-encoder.int8.onnx", "d24fb083ae3b1041fc24e97971d60e280c9342201fbb67b0ab428a8b4a51a434", 12937772, part = "encoder"),            ModelFile("tiny-decoder.int8.onnx", "$HF/sherpa-onnx-whisper-tiny/resolve/main/tiny-decoder.int8.onnx", "d2fece8dd42771f1df975c6c0445770d0c292bf7547c2cae04a6c0cc57540925", 89855401, part = "decoder"),            ModelFile("tiny-tokens.txt", "$HF/sherpa-onnx-whisper-tiny/resolve/main/tiny-tokens.txt", "b34b360dbb493e781e479794586d661700670d65564001f23024971d1f2fa126", 816730, part = "tokens"),        ),        standIn = true,        level = LEVELLING,    )    val sileroVad = ModelEntry(        id = "standin-silero-vad",        kind = "vad-silero",        role = "vad",        languages = listOf("*"),        files = listOf(            ModelFile("silero_vad.onnx", "https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/silero_vad.onnx", "9e2449e1087496d8d4caba907f23e0bd3f78d91fa552479bb9c23ac09cbb1fd6", 643854, part = "model"),        ),        standIn = true,        level = LEVELLING,    )    val all = listOf(zipformerEn, whisperTiny, sileroVad)    /** The live model for a language: the streaming one where there is one (English), else Whisper on segments. */    fun live(language: String): ModelEntry = if (language.substringBefore('-') == "en") zipformerEn else whisperTiny    /** The second pass: Whisper tiny re-reads an English sentence; elsewhere the live pass already is Whisper tiny. */    fun second(language: String): ModelEntry? = if (language.substringBefore('-') == "en") whisperTiny else null}