Beep detection
You can use the Wait element to aid leaving voice mails on answering machines by adding an extra parameter called beep
and setting it to true
.
Response
<Response>
<Wait length= "120" beep= "true" />
<Play> https://s3.amazonaws.com/plivocloud/Trumpet.mp3</Play>
</Response>
Explanation
In this example, upon the call being answered, the Wait element waits for 120 seconds for a beep sound to be received. If a beep sound is detected before the Wait length
times out, the Wait element ends and the Play verb is issued, and plays the specified MP3 file on the remote machine that sounded the beep.
If the Wait element times out after 120 seconds, the XML flow skips to the Play element.
Example Request
1
2
3
4
5
6
from plivo import plivoxml
response = ( plivoxml . ResponseElement ()
. add ( plivoxml . WaitElement ( None ). set_beep ( True ). set_length ( 10 ))
. add ( plivoxml . PlayElement ( 'https://s3.amazonaws.com/Trumpet.mp3' )))
print ( response . to_string ())
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
require 'rubygems'
require 'plivo'
include Plivo :: XML
include Plivo :: Exceptions
begin
response = Response . new
params = {
length: '120' ,
beep: true
}
response . addWait ( params )
play_url = 'https://s3.amazonaws.com/plivocloud/Trumpet.mp3'
response . addPlay ( play_url )
xml = PlivoXML . new ( response )
puts xml . to_xml
rescue PlivoXMLError => e
puts 'Exception: ' + e . message
end
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
var plivo = require ( ' plivo ' );
var response = plivo . Response ();
var params = {
' length ' : " 120 " ,
' beep ' : " true "
};
response . addWait ( params );
var play_url = " https://s3.amazonaws.com/plivocloud/Trumpet.mp3 " ;
response . addPlay ( play_url );
console . log ( response . toXML ());
/*
Sample Output
<Response>
<Wait length="120" beep="true"/>
<Play>
https://s3.amazonaws.com/plivocloud/Trumpet.mp3
</Play>
</Response>
*/
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
28
29
<?php
require '../vendor/autoload.php' ;
use Plivo\XML\Response ;
$response = new Response ();
$params = array (
'length' => "120" ,
'beep' => "true"
);
$response -> addWait ( $params );
$play_url = "https://s3.amazonaws.com/plivocloud/Trumpet.mp3" ;
$response -> addPlay ( $play_url );
Header ( 'Content-type: text/xml' );
echo ( $response -> toXML ());
/*
Sample Output
<Response>
<Wait length="120" beep="true"/>
<Play>
https://s3.amazonaws.com/plivocloud/Trumpet.mp3
</Play>
</Response>
*/
?>
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
// Example for wait - beep detection
package com.plivo.api.xml.samples.wait ;
import com.plivo.api.exceptions.PlivoXmlException ;
import com.plivo.api.xml.Play ;
import com.plivo.api.xml.Response ;
import com.plivo.api.xml.Wait ;
class BeepDetection {
public static void main ( String [] args ) throws PlivoXmlException {
Response response = new Response ()
. children (
new Wait ()
. beep ( true )
. length ( 10 ),
new Play ( "https://s3.amazonaws.com/Trumpet.mp3" )
);
System . out . println ( response . toXmlString ());
}
}
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
28
29
30
using System ;
using System.Collections.Generic ;
using Plivo.XML ;
namespace Plivo
{
class MainClass
{
public static void Main ( string [] args )
{
Plivo . XML . Response resp = new Plivo . XML . Response ();
resp . AddWait ( new Dictionary < string , string >()
{
{ "length" , "120" }, { "beep" , "true" }
});
resp . AddPlay ( "https://s3.amazonaws.com/abc.mp3" ,
new Dictionary < string , string >() { });
var output = resp . ToString ();
Console . WriteLine ( output );
}
}
}
//<Response>
// <Wait length = "120" beep="true" />
// <Play>https://s3.amazonaws.com/abc.mp3</Play>
//</Response>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Example for wait - beep detection
package main
import "github.com/plivo/plivo-go/v7/xml"
func main () {
response := xml . ResponseElement {
Contents : [] interface {}{
new ( xml . WaitElement ) .
SetBeep ( true ) .
SetLength ( 10 ),
new ( xml . PlayElement ) .
SetContents ( "https://s3.amazonaws.com/Trumpet.mp3" ),
},
}
print ( response . String ())
}
Example Request
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
28
from flask import Flask , Response , request
import plivoxml
app = Flask ( __name__ )
@ app . route ( '/wait/beep_detection/' , methods = [ 'GET' , 'POST' ])
def beep_detection ():
response = plivoxml . Response ()
params = {
'length' : "10" ,
'beep' : "true"
}
response . addWait ( ** params )
response . addPlay ( "https://s3.amazonaws.com/Trumpet.mp3" )
return Response ( str ( response ), mimetype = 'text/xml' )
if __name__ == "__main__" :
app . run ( host = '0.0.0.0' , debug = True )
# Sample Conference XML
# <Response>
# <Wait beep="true" length="10"/>
# <Play>
# https://s3.amazonaws.com/Trumpet.mp3
# </Play>
# </Response>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
require 'rubygems'
require 'plivo'
include Plivo
response = Response . new ()
params = {
'length' => "120" ,
'beep' => "true"
}
response . addWait ( params )
play_url = "https://s3.amazonaws.com/plivocloud/Trumpet.mp3"
response . addPlay ( play_url )
puts response . to_xml ()
=begin
Sample Output
<Response>
<Wait beep='true' length='120'/>
<Play>https://s3.amazonaws.com/plivocloud/Trumpet.mp3</Play>
</Response>
=end
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
var plivo = require ( ' plivo ' );
var response = plivo . Response ();
var params = {
' length ' : " 120 " ,
' beep ' : " true "
};
response . addWait ( params );
var play_url = " https://s3.amazonaws.com/plivocloud/Trumpet.mp3 " ;
response . addPlay ( play_url );
console . log ( response . toXML ());
/*
Sample Output
<Response>
<Wait length="120" beep="true"/>
<Play>
https://s3.amazonaws.com/plivocloud/Trumpet.mp3
</Play>
</Response>
*/
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
28
29
<?php
require '../vendor/autoload.php' ;
use Plivo\Response ;
$response = new Response ();
$params = array (
'length' => "120" ,
'beep' => "true"
);
$response -> addWait ( $params );
$play_url = "https://s3.amazonaws.com/plivocloud/Trumpet.mp3" ;
$response -> addPlay ( $play_url );
Header ( 'Content-type: text/xml' );
echo ( $response -> toXML ());
/*
Sample Output
<Response>
<Wait length="120" beep="true"/>
<Play>
https://s3.amazonaws.com/plivocloud/Trumpet.mp3
</Play>
</Response>
*/
?>
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.io.IOException ;
import com.plivo.helper.exception.PlivoException ;
import com.plivo.helper.xml.elements.Play ;
import com.plivo.helper.xml.elements.Wait ;
import com.plivo.helper.xml.elements.PlivoResponse ;
import javax.servlet.ServletException ;
import javax.servlet.http.HttpServlet ;
import javax.servlet.http.HttpServletRequest ;
import javax.servlet.http.HttpServletResponse ;
import org.eclipse.jetty.server.Server ;
import org.eclipse.jetty.servlet.ServletContextHandler ;
import org.eclipse.jetty.servlet.ServletHolder ;
public class beepDetection extends HttpServlet {
private static final long serialVersionUID = 1L ;
@Override
protected void doGet ( HttpServletRequest req ,
HttpServletResponse resp )
throws ServletException , IOException {
PlivoResponse response = new PlivoResponse ();
Wait wait = new Wait ();
wait . setLength ( 120 );
wait . setBeep ( true );
Play play = new
Play ( "https://s3.amazonaws.com/plivocloud/Trumpet.mp3" );
try {
response . append ( wait );
response . append ( play );
System . out . println ( response . toXML ());
resp . addHeader ( "Content-Type" , "text/xml" );
resp . getWriter (). print ( response . toXML ());;
} catch ( PlivoException e ) {
e . printStackTrace ();
}
}
public static void main ( String [] args ) throws Exception {
String port = System . getenv ( "PORT" );
if ( port == null )
port = "8000" ;
Server server = new Server ( Integer . valueOf ( port ));
ServletContextHandler context = new
ServletContextHandler ( ServletContextHandler . SESSIONS );
context . setContextPath ( "/" );
server . setHandler ( context );
context . addServlet ( new
ServletHolder ( new
beepDetection ()), "/wait/beep_detection" );
server . start ();
server . join ();
}
}
/*
Sample Output
<Response>
<Wait beep="true" length="120"/><
Play>https://s3.amazonaws.com/plivocloud/Trumpet.mp3</Play>
</Response>
*/
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
28
29
30
using System ;
using System.Collections.Generic ;
using Plivo.XML ;
namespace Plivo
{
class MainClass
{
public static void Main ( string [] args )
{
Plivo . XML . Response resp = new Plivo . XML . Response ();
resp . AddWait ( new Dictionary < string , string >()
{
{ "length" , "120" }, { "beep" , "true" }
});
resp . AddPlay ( "https://s3.amazonaws.com/abc.mp3" ,
new Dictionary < string , string >() { });
var output = resp . ToString ();
Console . WriteLine ( output );
}
}
}
//<Response>
// <Wait length = "120" beep="true" />
// <Play>https://s3.amazonaws.com/abc.mp3</Play>
//</Response>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Example for wait - beep detection
package main
import "github.com/plivo/plivo-go/v7/xml"
func main () {
response := xml . ResponseElement {
Contents : [] interface {}{
new ( xml . WaitElement ) .
SetBeep ( true ) .
SetLength ( 10 ),
new ( xml . PlayElement ) .
SetContents ( "https://s3.amazonaws.com/Trumpet.mp3" ),
},
}
print ( response . String ())
}
🥳 Thank you! It means a lot to us!
Help Us Improve
Thank you so much for rating the page, we would like to get your input
for further improvements!
Thank you for your feedback!