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/Store.kt (2450 bytes)

1 package com.honjimaku.subrep
2 
3 import android.content.Context
4 
5 /** What the user chose. It stays when the app stops. */
6 class Store(context: Context) {
7 
8     private val prefs = context.getSharedPreferences("subrep", Context.MODE_PRIVATE)
9 
10     /** The id of the speech model, see [Model]. */
11     var model: String
12         get() = prefs.getString("model", Model.BASE.id).orEmpty()
13         set(value) = prefs.edit().putString("model", value).apply()
14 
15     var lang: String
16         get() = prefs.getString("lang", "ja").orEmpty()
17         set(value) = prefs.edit().putString("lang", value.trim().lowercase().ifEmpty { "auto" }).apply()
18 
19     /** True: the sound of the apps on this device. False: the microphone. */
20     var screen: Boolean
21         get() = prefs.getBoolean("screen", true)
22         set(value) = prefs.edit().putBoolean("screen", value).apply()
23 
24     /** Send the captions to the share link. Off until the user turns it on. */
25     var share: Boolean
26         get() = prefs.getBoolean("share", false)
27         set(value) = prefs.edit().putBoolean("share", value).apply()
28 
29     /** What the viewers see as the name of the stream. */
30     var title: String
31         get() = prefs.getString("title", "").orEmpty()
32         set(value) = prefs.edit().putString("title", value.trim().take(80)).apply()
33 
34     /** True: the cloud makes the captions, with hours from subread.space. False: the phone. */
35     var cloud: Boolean
36         get() = prefs.getBoolean("cloud", false)
37         set(value) = prefs.edit().putBoolean("cloud", value).apply()
38 
39     /** The device cookie of subread.space: the account that holds the cloud hours. */
40     var device: String
41         get() = prefs.getString("device", "").orEmpty()
42         set(value) = prefs.edit().putString("device", value).apply()
43 
44     var overlay: Boolean
45         get() = prefs.getBoolean("overlay", true)
46         set(value) = prefs.edit().putBoolean("overlay", value).apply()
47 
48     /** The room on the relay. Made once, so the link stays the same. */
49     val room: String
50         get() = prefs.getString("room", null) ?: newRoom()
51 
52     val secret: String
53         get() = prefs.getString("secret", null) ?: newRoom().let { prefs.getString("secret", "").orEmpty() }
54 
55     /** A new room: the old link stops. Returns the new room id. */
56     fun newRoom(): String {
57         val room = Room.newId()
58         prefs.edit().putString("room", room).putString("secret", Room.newSecret()).apply()
59         return room
60     }
61 }