aws-samples / aws-samples/amazon-nova-samples
Kotlin sample for speech-to-speech
- Dominant language
- Jupyter Notebook
- Stars
- 452
- Forks
- 266
- PR merge metrics
- No merged PRs in 30d
Description
Is there a plan to add a Kotlin variant of the sample Nova Sonic app? I'm trying to use the Kotlin SDK on Android, and using the Java sample as a guide, but struggling. I have a problem with Flows versus MutableSharedFlows. The following code works, but isn't what I need. I need to change the Flow to a MutableSharedFlow to be able to emit new values in the future as the conversation with bedrock progresses. But when I use a MutableSharedFlow, it doesn't work.
```
val events = flow {
emit(InvokeModelWithBidirectionalStreamInput.Chunk(
value = BidirectionalInputPayloadPart {
this.bytes = SessionStart.toByteArray()
}
))}
val request = InvokeModelWithBidirectionalStreamRequest {
this.modelId = "amazon.nova-sonic-v1:0"
this.body = events
}
bedrockClient.invokeModelWithBidirectionalStream(request) { response ->
println("Response: $response")
}
```
Whereas if the following doesn't work.
```
val events: MutableSharedFlow = MutableSharedFlow(
replay = 1,
extraBufferCapacity = 10
)
events.emit(InvokeModelWithBidirectionalStreamInput.Chunk(
value = BidirectionalInputPayloadPart {
this.bytes = SessionStart.toByteArray()
}))
/* Same code below as for the cold flow. */
val request = InvokeModelWithBidirectionalStreamRequest {
this.modelId = "amazon.nova-sonic-v1:0"
this.body = events
}
bedrockClient.invokeModelWithBidirectionalStream(request) { response ->
println("Response: $response")
}
```
Even though I have replay set in the hot flow, it doesn't work, and I have tried wrapping code in launch, and making sure the emit is called after collect by using onSubscription. And I have put delays in the code. In all cases the AWS SDK doesn't perform any HTTP transactions, whereas it does with the cold flow? I have also tried callbackFlows etc, and still no success.
Contributor guide
Assessment
This issue has not been assessed yet.