Speech Synthesis Markup Language (SSML) provides a standard way to mark up text for the generation of synthesized speech. It supports 27 languages and more than 40 voices, and allows developers to control pronunciation, pitch, and volume.
For more information on SSML, see Getting Started with SSML.
Speak elements with SSML can be nested inside GetDigits and GetInput XML element tags.
<Response>
<Speak voice="Polly.Amy">
<prosody rate="medium">
Hello and welcome to the Plivo text-to-speech engine.
<break/>
<break/>
We’re now testing the
<say-as interpret-as="spell-out">SSML</say-as>
feature.
</prosody>
</Speak>
</Response>
<Response>
<GetDigits numDigits="1" playBeep="true">
<Speak voice="Polly.Salli">
<prosody rate="fast">
Please press 1 to proceed.
<break/>
<break/>
We’re now testing the
<say-as interpret-as="spell-out">SSML</say-as>
feature.
</prosody>
</Speak>
</GetDigits>
</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
from flask import Flask, Response, request, url_for
from plivo import plivoxml
app = Flask(__name__)
@app.route("/ssml/", methods=["GET", "POST"])
def ssml():
element = plivoxml.ResponseElement()
response = (
element.add(
plivoxml.SpeakElement(content="The word", voice="Polly.Joey", language="en-US")
.add_say_as("read", interpret_as="characters")
.add_s("may be interpreted as either the present simple form")
.add_w("read", role="amazon:VB")
.add_s("or the past participle form")
.add_w("read", role="amazon:VBD")
)
.to_string(False)
)
print(response)
return Response(response, mimetype="text/xml")
if __name__ == "__main__":
app.run(host="0.0.0.0", debug=True)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class PlivoController < ApplicationController
def ssml
response = Plivo::XML::Response.new
speak_elem = response.addSpeak('The word', voice: 'Polly.Joey', language: 'en-US')
speak_elem.addSayAs('read', 'interpret-as' => 'characters')
speak_elem.addS('may be interpreted as either the present simple form')
speak_elem.addW('read', 'role' => 'amazon:VB')
speak_elem.addS('or the past participle form')
speak_elem.addW('read', 'role' => 'amazon:VBD')
xml = Plivo::XML::PlivoXML.new(response)
puts xml.to_xml()
render xml: xml.to_xml
end
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
25
26
27
28
29
30
31
32
33
34
35
var plivo = require('plivo');
var express = require('express');
var app = express();
app.set('port', (process.env.PORT || 5000));
app.use(express.static(__dirname + '/public'));
app.all('/ssml/', function (request, response) {
if (request.method == "GET") {
var r = new plivo.Response();
const speakElem = r.addSpeak('The word', {
'voice': 'Polly.Joey',
'language': 'en-US'
});
speakElem.addSayAs('read', {
'interpret-as': 'characters'
});
speakElem.addS('may be interpreted as either the present simple form');
speakElem.addW('read', {
'role': 'amazon:VB'
});
speakElem.addS('or the past participle form');
speakElem.addW('read', {
'role': 'amazon:VBD'
});
console.log(r.toXML());
response.set({
'Content-Type': 'text/xml'
});
response.end(r.toXML());
}
});
app.listen(app.get('port'), function () {
console.log('Node app is running on port', app.get('port'));
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
namespace App\Http\Controllers;
require '../vendor/autoload.php';
use Plivo\RestClient;
use Plivo\XML\Response;
use Illuminate\Http\Request;
class ReceivecallController extends Controller
{
public function ssml()
{
$response = new Response();
$speak_elem = $response->addSpeak('The word', ['language'=>"en-US", 'voice'=>"Polly.Joey"]);
$speak_elem->addSayAs('read', ['interpret-as'=>"characters"]);
$speak_elem->addS('may be interpreted as either the present simple form');
$speak_elem->addW('read', ['role'=>"amazon:VB"]);
$speak_elem->addS('or the past participle form');
$speak_elem->addW('read', ['role'=>"amazon:VBD"]);
$xml_response = $response->toXML();
return response($xml_response, 200)->header('Content-Type', 'application/xml');
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package com.example.SsmlHandler;
import com.plivo.api.exceptions.PlivoXmlException;
import com.plivo.api.xml.*;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.*;
@SpringBootApplication
@RestController
public class SsmlApplication {
public static void main(String[] args) {
SpringApplication.run(SsmlHandlerApplication.class, args);
}
@RequestMapping(value = "/ssml/", produces = { "application/xml" }, method = { RequestMethod.GET, RequestMethod.POST })
public Response Ssml() throws PlivoXmlException {
Response response = new Response().children(new Speak("The word","Polly.Joey","en-US",1)
.children(new SayAs("read", "characters"))
.addS("may be interpreted as either the present simple form")
.addW("read", "amazon:VB")
.addS("or the past participle form")
.addW("read", "amazon:VBD"));
System.out.println(response.toXmlString());
return 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
using System.Collections.Generic;
using Plivo.XML;
using Microsoft.AspNetCore.Mvc;
namespace Voicemail.Controllers
{
public class SsmlController : Controller
{
// GET: /<controller>/
public IActionResult Index()
{
var resp = new Response();
Speak speak_elem = new Speak("The word", new Dictionary<string, string>() {
{"voice","Polly.Joey"},
{"language","en-US"},
});
resp.Add(speak_elem);
speak_elem.AddSayAs("read", new Dictionary<string, string>() {
{ "interpret-as", "characters" }
});
speak_elem.AddS("may be interpreted as either the present simple form");
speak_elem.AddW("read", new Dictionary<string, string>() {
{ "role", "amazon:VB" }
});
speak_elem.AddS("or the past participle form");
speak_elem.AddW("read", new Dictionary<string, string>() {
{ "role", "amazon:VBD" }
});
var output = resp.ToString();
return this.Content(output, "text/xml");
}
}
}
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
package main
import (
"net/http"
"github.com/go-martini/martini"
"github.com/plivo/plivo-go/v7/xml"
)
func main() {
m := martini.Classic()
m.Any("/ssml/", func(w http.ResponseWriter, r *http.Request) string {
w.Header().Set("Content-Type", "application/xml")
response := xml.ResponseElement{
Contents: []interface{}{
new(xml.SpeakElement).
AddSpeak("The word", "Polly.Joey", "en-US", 1).
AddSayAs("read", "characters", "").
AddS("may be interpreted as either the present simple form").
AddW("read", "amazon:VB").
AddS("or the past participle form").
AddW("read", "amazon:VBD"),
},
}
return response.String()
})
m.Run()
}