Recently Written · git

subrep-android

Subrep on Android: live captions of the sound of the phone, made on the phone by Whisper, shared by link.

git clone https://github.com/equwal/subrep-android

Log | Files | Refs


app/src/main/kotlin/com/honjimaku/subrep/Recognizer.kt (962 bytes)

1 package com.honjimaku.subrep
2 
3 /** Turns one piece of speech into text: Whisper on the phone, or [CloudRecognizer]. */
4 interface Recognizer : AutoCloseable {
5 
6     /** The language found in the last piece, "ja", "ru", ..., or "" when not known. */
7     val detectedLanguage: String
8 
9     /** The text of [samples]: 16 kHz mono, from -1 to 1. [language] is a code, or "auto". */
10     fun transcribe(samples: FloatArray, language: String): String
11 }
12 
13 /** Recognition on subread.space. Each piece costs its length in seconds from the hours of the account. */
14 class CloudRecognizer(private val cloud: Cloud, private val onSecondsLeft: (Long) -> Unit) : Recognizer {
15 
16     override val detectedLanguage: String = ""
17 
18     override fun transcribe(samples: FloatArray, language: String): String {
19         val answer = cloud.transcribe(Pcm.toBytes(samples), language)
20         onSecondsLeft(answer.secondsLeft)
21         return answer.text
22     }
23 
24     override fun close() = Unit
25 }