Use the ngrok URL as above (don't forget the /twiml at the end), and since we used the annotation @GetMapping in the code, redefine the method to HTTP GET : Screenshot of Twilio console configuring inbound calls Save this configuration and you are ready to call the number. A cat with sunglasses. Caption "I'm ready" Call your new phone number.
You hear a robot read <Say>, then Media Stream starts and the console displays something similar to this as you speak: Bash Copy the code New connection has been established Message received, length is 57 Message received, length is 338 Message received, length is 374 .
.. Many more lines like this ... Message received, philippines mobile number example length is 379 Message received, length is 194 Connection closed Congratulations, you have a working WebSocket server with Spring Boot, receiving live audio from a phone call to your Twilio number.
There are a lot of things you can do with the audio stream. The next part of this article will present an example: transferring the data to Google's text-to-speech service for live transcription. Streaming data to Google's transcription service Google's text-to-speech service can accept streaming data, making it a perfect fit for our project.
To use it, you set up a project and upload your credentials to a file whose location is stored in the environment variable GOOGLE_APPLICATION_CREDENTIALS .
It's free, but you need a credit card to create the account. You can follow Google's instructions to do all this . I'll grab a cup of tea and wait for your feedback. A steaming cup of tea Now that you have set up your Google project, we can continue. You need to add a new class to extract data from Twilio's WebSocket messages and send them to Google in the correct format.
Based on Google's sample code , I created a class that can be copied from the repo on GitHub and used directly. Keep in mind that your package name will probably be different depending on what you chose for the group and artifact at the beginning. Your IDE should help you here. You need to add some additional dependencies in your pom.
Many more lines like this .
-
- Posts: 9
- Joined: Sun Dec 22, 2024 4:43 am