/
TwimlRestController.java
27 lines (22 loc) · 981 Bytes
/
TwimlRestController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package com.example.twilio.mediastreamsazuretranscription;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Pause;
import com.twilio.twiml.voice.Say;
import com.twilio.twiml.voice.Start;
import com.twilio.twiml.voice.Stream;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class TwimlRestController {
@PostMapping(value = "/twiml", produces = "application/xml")
@ResponseBody
public String getStreamsTwiml() {
String wssUrl = "WEBSOCKET_URL";
return new VoiceResponse.Builder()
.say(new Say.Builder("Hello! Start talking and the live audio will be streamed to your app").build())
.start(new Start.Builder().stream(new Stream.Builder().url(wssUrl).build()).build())
.pause(new Pause.Builder().length(30).build())
.build().toXml();
}
}