Page 1 of 1

As for ngrok, it should still be running.

Posted: Sun Dec 22, 2024 9:38 am
by poxoja9630
gilliard.websocketstranscription; import org.springframework.web.socket.CloseStatus; import org.

springframework.web.socket.TextMessage; import org.springframework.web.socket.WebSocketSession; import org.springframework.web.socket.handler.AbstractWebSocketHandler; import java.util.HashMap; import java.util.Map; public class TwilioMediaStreamsHandler extends AbstractWebSocketHandler { private Map<WebSocketSession, GoogleTextToSpeechService> sessions = new HashMap<>(); @Override public void afterConnectionEstablished(WebSocketSession session) throws Exception { sessions.put(session, new GoogleTextToSpeechService( transcription -> { System.out.println("Transcription: " + transcription); } )); } @Override protected void handleTextMessage(WebSocketSession session, TextMessage textMessage) { sessions.

get(session).send(message.getPayload()); } @Override public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception { sessions.get(session).close(); sessions.remove(session); } } On line 13, a Map from WebSocketSession to GoogleTextToSpeechService is created, so that it is possible to support multiple incoming calls simultaneously without confusing Google by mixing all the audio streams.

Then, on line 26, the payload of each incoming message is sent to GoogleTextToSpeechService, which is configured to print the transcript whenever Google sends it.



As for ngrok, it should still be running. If philippines mobile number example not, restart it with ngrok http 8080. Restart the server with ./mvnw spring-boot:run and call your number again. After the voice message, you can speak and you will see something like this in your console: Text Copy the code Transcription: Google Transcription: Google is Transcription: Google is Transcription: Google is transcribing Transcription: Google is transcribing Transcription: Google is transcribing Transcription: Google is transcribing the Transcription: Google is transcribing the live audio Transcription: Google is transcribing the live audio Transcription: Google is transcribing the live audio Transcription: Google is transcribing the live audio from Transcription: Google is transcribing the live audio from Transcription: Google is transcribing the live audio from Transcription: Google is transcribing the live audio from this Transcription: Google is transcribing the live audio from this phone call.

Image

Isn't it amazing what you can achieve with a few classes and some powerful cloud services? The next step? There are a myriad of possibilities: you can stream the text to a translation service , save it to a file , try your hand at sentiment analysis , or choose keywords that can trigger a follow-up text message after the call.