-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there any way of using two way communication on any cable. #1
Comments
@zamananjum0 Did you figure this out? Looking at the AnyCable code, this demo utilizes a custom executor to handle incoming messages on the WS but doesn't appear to have a similar model in place for some custom handler to send messages back via WS. Am I wrong? |
@palkan It would be amazing to get your input on if/how this can be accomplished. Thank you for the excellent demo! |
Hey there, Sorry, I didn't have notifications tuned on for this repo, so missed this one. There are two ways you can implement bi-directional communication:
|
That's great, @palkan. Thank you! For my project, I'm inclined to keep the business logic in Rails as long as possible, so option #2 here would be great. But I found that if I simply broadcast my data from Rails in the form of a The logs suggest that the broadcast was scheduled, but no outbound audio is played in the stream and I'm not sure how to "see" what the message relayed by AnyCable looked like. I get:
I wonder if this is because we need our custom encoder to do something with the message payload from Rails? Or perhaps we need to specify a |
Let me answer my own question: This example app actually contains everything you need for bi-directional communication with Twilio media streams. I just needed to learn some Go. Thank you, @palkan and @irinanazarova! The encoder's Although I have not yet figured out how to include this metadata in my default Rails ActionCable broadcasts (tips appreciated!) I can see that by tweaking the Go code to assume the |
@junket Thanks for sharing your insights!
Something like this should work: AnyCable::Rails.with_broadcast_options(broadcast_type: "...") do
code_that_performs_broadcasts
end Or you can directly use AnyCable: |
One thing I'm exploring (and would love to hear your take @palkan) is the ideal audio chunk size when streaming from ActionCable to AnyCable-Go. My first successful stream used 20ms (160 byte) chunks of 8000Khz mu-law and came through cleanly in local development. However, on all subsequent tries, ActionCable seemed unable to send the chunks quickly enough, leading to unusable choppy audio. Is that an ActionCable performance bottleneck? Weird that it had been more performant. My code is a simple test chunking a small file like:
If I up the chunk size to 200ms, ActionCable can keep and the audio is better. I assume there are trade-offs here but I am too much of a newb to really know what they are 😊 |
I think, the reason is in added network latency: 20ms of audio can be processed faster than the next 20ms arrive; when you send in a larger chunks, the network latency is about the same, but there is a buffer still full of audio from the previous chunk. |
Yep, this has to be it. I switched my broadcast URL from ngrok to localhost and the latency was virtually gone. I'll experiment with ideal chunk size. I assume there is an upper limit, but I don't know. |
I need help on bidirectional chat system where we can use twilio, and AI agent can communicate with the caller.
The text was updated successfully, but these errors were encountered: