Articles
Android — Send live audio stream from client to server using WebSocket and OkHttp client

A long time back, I was looking for a solution to send a live audio stream from an android device to a backend server. After lots of effort, I finally made it work.
In this article, you will learn how to stream live audio from client to server using OkHttp client & WebSocket.
So, the second option is to go with Websocket which provides bi-directional communication over a single TCP connection. Websocket is suitable for applications that need to communicate with real-time events.
It’s important to take into consideration that WebSocket does not use http://
or https://
schema, rather it use ws://
or wss://
schema.
Here’s our app, we implemented Shazam like functionality by streaming audio from android phone MIC to the server to identify music playing around us.
Okay, enough discussion.
To make a blog post to the point and easy to understand, I have divided it into small steps.
Also, we’re not going to cover UI-related parts in this blog post, we’ll only discuss business logic to do live audio streaming. However, if you are interested in how to make that wave animation, check out our article on Jetpack compose animation examples.
Alright, let’s get started!
Contents:
- Add Required permission
- Add required dependencies
- Setup AudioRecorder
- Setup WebSocket client
- Create a request
- Create WebSocket
- Send recorded bytes to the server
Full Article: Radhika S @ Canopas
