refactor: remove deprecated transcript api
Signed-off-by: rhunk <101876869+rhunk@users.noreply.github.com>
This commit is contained in:
@@ -1056,14 +1056,6 @@
|
||||
"preferred_transcription_lang": {
|
||||
"name": "Preferred Transcription Language",
|
||||
"description": "The preferred language for the voice note transcript (e.g. EN, ES, FR)"
|
||||
},
|
||||
"enhanced_transcript": {
|
||||
"name": "Enhanced Transcript",
|
||||
"description": "Improves the voice note transcript using DeepL.\nBefore using this feature, please ensure that you have read their privacy policy."
|
||||
},
|
||||
"enhanced_transcript_in_notifications": {
|
||||
"name": "Enhanced Transcript in Notifications",
|
||||
"description": "Transcribes voice notes in notifications using DeepL. This requires the Chat Preview feature to be enabled in Better Notifications"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -20,8 +20,6 @@ class Experimental : ConfigContainer() {
|
||||
class BetterTranscriptConfig: ConfigContainer(hasGlobalState = true) {
|
||||
val forceTranscription = boolean("force_transcription") { requireRestart() }
|
||||
val preferredTranscriptionLang = string("preferred_transcription_lang") { requireRestart() }
|
||||
val enhancedTranscript = boolean("enhanced_transcript") { requireRestart(); addNotices(FeatureNotice.UNSTABLE) }
|
||||
val enhancedTranscriptInNotifications = boolean("enhanced_transcript_in_notifications") { requireRestart(); addNotices(FeatureNotice.UNSTABLE) }
|
||||
}
|
||||
|
||||
class ComposerHooksConfig: ConfigContainer(hasGlobalState = true) {
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
package me.rhunk.snapenhance.common.util
|
||||
|
||||
import com.google.gson.JsonParser
|
||||
import me.rhunk.snapenhance.common.Constants
|
||||
import okhttp3.Headers
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.RequestBody
|
||||
|
||||
|
||||
class TranscriptApi(
|
||||
private val okHttpClient: OkHttpClient = OkHttpClient.Builder().addInterceptor {
|
||||
it.proceed(it.request().newBuilder().header("User-Agent", Constants.USER_AGENT).build())
|
||||
}.build()
|
||||
) {
|
||||
private fun genDlClearance() = okHttpClient.newCall(
|
||||
Request("https://clearance.deepl.com/token".toHttpUrl())
|
||||
).execute().use { response ->
|
||||
val cookie = response.headers.firstOrNull { it.first.lowercase() == "set-cookie" && it.second.contains("dl_clearance", ignoreCase = true) }
|
||||
cookie?.second?.substringBefore(";")?.substringAfter("dl_clearance=")
|
||||
}
|
||||
|
||||
fun transcribe(
|
||||
body: RequestBody,
|
||||
lang: String? = null,
|
||||
): String? {
|
||||
val clearance = genDlClearance() ?: return null
|
||||
val url = "https://voice-pro.www.deepl.com/sync/transcribe".toHttpUrl().newBuilder()
|
||||
.apply {
|
||||
lang?.let { addQueryParameter("lang", it) }
|
||||
}
|
||||
.build()
|
||||
val request = Request(url, headers = Headers.headersOf(
|
||||
"Cookie", "dl_clearance=$clearance",
|
||||
"Content-Type", "audio/webm"
|
||||
), method = "POST", body = body)
|
||||
return okHttpClient.newCall(request).execute().use { response ->
|
||||
if (!response.isSuccessful) return@use null
|
||||
val jsonObject = JsonParser.parseString(response.body.string()).asJsonObject
|
||||
jsonObject.getAsJsonArray("segments").fold("") { text, segment ->
|
||||
text + segment.asJsonObject.getAsJsonPrimitive("text").asString
|
||||
}.trim()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user