Skip to content

Commit 7004a99

Browse files
committed
make it openai compatible
1 parent 14ec5dd commit 7004a99

File tree

2 files changed

+8
-20
lines changed

2 files changed

+8
-20
lines changed

app/build.gradle.kts

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ android {
1111
applicationId = "it.eja.ttsserver"
1212
minSdk = 24
1313
targetSdk = 34
14-
versionCode = 4
15-
versionName = "1.6.2"
14+
versionCode = 5
15+
versionName = "1.6.5"
1616

1717
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
1818
vectorDrawables {

app/src/main/java/it/eja/ttsserver/MainActivity.kt

+6-18
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,12 @@ class MainActivity : Activity(), TextToSpeech.OnInitListener {
109109
if (contentType == "application/json") {
110110
val requestBody = readRequestBody(reader, contentLength)
111111
val json = JSONObject(requestBody)
112-
val text = json.optString("text", "")
112+
var text = json.optString("text", "")
113113
val locale = parseLocale(json.optString("locale", ""))
114-
114+
val input = json.optString("input", "")
115+
if (input.isNotEmpty()) {
116+
text = input
117+
}
115118
if (text.isNotEmpty()) {
116119
synthesizeTextToAudio(text, locale)
117120
while (!synthesisDone) {
@@ -153,21 +156,6 @@ class MainActivity : Activity(), TextToSpeech.OnInitListener {
153156
}
154157
}
155158

156-
157-
private fun getContentLength(reader: BufferedReader): Int {
158-
var contentLength = 0
159-
while (true) {
160-
val line = reader.readLine() ?: break
161-
if (line.startsWith("Content-Length:")) {
162-
contentLength = line.substringAfter("Content-Length:").trim().toInt()
163-
}
164-
if (line.isEmpty()) {
165-
break
166-
}
167-
}
168-
return contentLength
169-
}
170-
171159
private fun readRequestBody(reader: BufferedReader, contentLength: Int): String {
172160
val charArray = CharArray(contentLength)
173161
reader.read(charArray, 0, contentLength)
@@ -345,4 +333,4 @@ class MainActivity : Activity(), TextToSpeech.OnInitListener {
345333
}
346334
return ip
347335
}
348-
}
336+
}

0 commit comments

Comments
 (0)