Skip to content

Commit

Permalink
feat: Voice TTS
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani committed Jun 28, 2024
1 parent e5d7383 commit b0e5243
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main/kotlin/com/vonage/client/kt/Voice.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down
48 changes: 48 additions & 0 deletions src/test/kotlin/com/vonage/client/kt/VoiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,22 @@ class VoiceTest : AbstractTest() {
assertEquals(callIdStr, response.uuid)
}

private fun testTextToSpeech(expectedRequestParams: Map<String, Any>? = 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)
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit b0e5243

Please sign in to comment.