Download the PHP package techworker/ssml without Composer
On this page you can find all versions of the php package techworker/ssml. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package ssml
techworker/ssml
This library allows you to easily generate Speech Synthesis Markup Language (SSML) with PHP.
Usage
This library provides a fluent interface to build SSML strings. It tries to offer all elements that are defined in the specification, but since most of the synthesizers are satisfied with a "simple" SSML subset or some are bending the specification to it's own needs, this library does not force you into the specification and even offers you ways to go beyond the specification.
It ships with a SSML validator for Amazon Alexa.
So in short:
You are able to generate the SSML that adhere's to the SSML specification, but it is simple to avoid the rules and generate what you need.
Code peek
outputs
Installation
Add this to your composer.json
.. or use the following command on your command line:
composer require techworker/ssml
After that, you can immediately start to build your SSML.
The fluent interface
To get started, you'll have to create a new speak
(root) element. This can be done in numerous ways, but the preferred way is to use the \Techworker\Ssml\SsmlBuilder
class.
This will give you a new Element called Speak
(which ends up as a <speak>
node) and you can go on from here to add additional nodes.
To give you an example on how you can use the library:
This command will end up as:
There are two different types of elements. One element type is the container element. This is an element that can contain other elements.
The other type is a leaf element which is not capable of holding other elements as children.
If you add a container element with the fluent interface, you will get the container element itself back and can continue to add child elements to the container.
If you add a leaf element, you will get back the container element, that hosts
the previously added leaf element. So to fetch the leaf element, you'll have
to call the fetch
method.
Example
There are 2 helper functions up
and root
to help you to traverse up in the
element tree.
Example
Supported Elements (tags)
SSML is used by various parties and some are just using a subset of the specification and some are extending the specification to it's needs. The following list describes the elements + attributes which are natively supported. Elements that are missing an attribute of your choice or are absent completely can still be created.
speak
A SSML string is always surrounded by a <speak>
tag. It will be created automatically, whenever you call the \Techworker\Ssml\SsmlBuilder::factory();
method.
Outputs
audio
Example
Outputs
break
Example
Outputs
p (paragraph)
Example
Outputs
s (sentence)
Example
Outputs
phoneme
Example
Outputs
say-as
Example
Outputs
The format attribute is empty if not provided or set to null
.
w (word)
Example
Outputs
Custom elements
If you need a custom element for a synthesizer that adds additional elements to the specification, you can simply create them.
Example
Outputs
Custom attributes
If you need to add another attribute to an element that is not supported yet,
you can use the attr
function on the element.
Example
Outputs
Validation
To validate the resulting SSML against specifications from a vendor, you can use specification validators.
This library ships with a Amazon Alexa validator.