diff --git a/src/main/kotlin/com/vonage/client/kt/Voice.kt b/src/main/kotlin/com/vonage/client/kt/Voice.kt index 3f0c3a1..1534b9c 100644 --- a/src/main/kotlin/com/vonage/client/kt/Voice.kt +++ b/src/main/kotlin/com/vonage/client/kt/Voice.kt @@ -40,13 +40,18 @@ class Voice(private val voiceClient: VoiceClient) { else voiceClient.startStream(callId, streamUrl) fun stopStream(): StreamResponse = voiceClient.stopStream(callId) + + fun startTalk(text: String, properties: (TalkPayload.Builder.() -> Unit) = {}): TalkResponse = + voiceClient.startTalk(callId, TalkPayload.builder(text).apply(properties).build()) + + fun stopTalk(): TalkResponse = voiceClient.stopTalk(callId) } fun listCalls(filter: (CallsFilter.Builder.() -> Unit)? = null): CallInfoPage = if (filter == null) voiceClient.listCalls() else voiceClient.listCalls(CallsFilter.builder().apply(filter).build()) - fun createCall(call: (Call.Builder.() -> Unit)): CallEvent = + fun createCall(call: Call.Builder.() -> Unit): CallEvent = voiceClient.createCall(Call.builder().apply(call).build()) } diff --git a/src/test/kotlin/com/vonage/client/kt/VoiceTest.kt b/src/test/kotlin/com/vonage/client/kt/VoiceTest.kt index 7ae3318..dd74b46 100644 --- a/src/test/kotlin/com/vonage/client/kt/VoiceTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/VoiceTest.kt @@ -138,6 +138,22 @@ class VoiceTest : AbstractTest() { assertEquals(callIdStr, response.uuid) } + private fun testTextToSpeech(expectedRequestParams: Map? = null, invocation: () -> TalkResponse) { + val message = if (expectedRequestParams != null) "started" else "stopped" + val expectedResponseParams = mapOf("message" to message, "uuid" to callIdStr) + val talkUrl = "$callUrl/talk" + if (expectedRequestParams != null) { + mockPut(talkUrl, expectedRequestParams, expectedResponseParams = expectedResponseParams) + } + else { + mockDelete(talkUrl, AuthType.JWT, expectedResponseParams) + } + val response = invocation.invoke() + assertNotNull(response) + assertEquals(message, response.message) + assertEquals(callIdStr, response.uuid) + } + @Test fun `terminate call`() { testModifyCall("hangup", callObj::hangup) @@ -221,6 +237,38 @@ class VoiceTest : AbstractTest() { testStream() } + @Test + fun `play text to speech all parameters`() { + val style = 1 + val premium = true + val loop = 3 + val level = 0.65 + testTextToSpeech(mapOf( + "text" to text, "language" to "en-GB-SCT", + "style" to style, "premium" to premium, + "loop" to loop, "level" to level + )) { + callObj.startTalk(text) { + language(TextToSpeechLanguage.SCOTTISH_ENGLISH) + style(style); premium(premium); loop(loop); level(level) + } + } + } + + @Test + fun `play text to speech text only`() { + testTextToSpeech(mapOf("text" to text)) { + callObj.startTalk(text) + } + } + + @Test + fun `stop text to speech`() { + testTextToSpeech { + callObj.stopTalk() + } + } + @Test fun `list calls all filter parameters`() { mockGet(callsBaseUrl, expectedQueryParams = mapOf(