@@ -109,9 +109,12 @@ class MainActivity : Activity(), TextToSpeech.OnInitListener {
109
109
if (contentType == " application/json" ) {
110
110
val requestBody = readRequestBody(reader, contentLength)
111
111
val json = JSONObject (requestBody)
112
- val text = json.optString(" text" , " " )
112
+ var text = json.optString(" text" , " " )
113
113
val locale = parseLocale(json.optString(" locale" , " " ))
114
-
114
+ val input = json.optString(" input" , " " )
115
+ if (input.isNotEmpty()) {
116
+ text = input
117
+ }
115
118
if (text.isNotEmpty()) {
116
119
synthesizeTextToAudio(text, locale)
117
120
while (! synthesisDone) {
@@ -153,21 +156,6 @@ class MainActivity : Activity(), TextToSpeech.OnInitListener {
153
156
}
154
157
}
155
158
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
-
171
159
private fun readRequestBody (reader : BufferedReader , contentLength : Int ): String {
172
160
val charArray = CharArray (contentLength)
173
161
reader.read(charArray, 0 , contentLength)
@@ -345,4 +333,4 @@ class MainActivity : Activity(), TextToSpeech.OnInitListener {
345
333
}
346
334
return ip
347
335
}
348
- }
336
+ }
0 commit comments