play

View as MarkdownOpen in Claude

Add a play verb to the main section. Plays audio from a URL or a list of URLs.

Exactly one of url or urls must be provided. Calling play() without either raises a ValueError.

Parameters

url
Optional[str]

Single URL to play. Supports audio file URLs and the say: prefix for text-to-speech (e.g., "say:Hello world"). Mutually exclusive with urls.

urls
Optional[list[str]]

List of URLs to play in sequence. Mutually exclusive with url.

volume
Optional[float]

Volume adjustment level, from -40 to 40 dB.

say_voice
Optional[str]

Voice name for text-to-speech playback.

say_language
Optional[str]

Language code for text-to-speech (e.g., "en-US").

say_gender
Optional[str]

Gender for text-to-speech voice selection.

auto_answer
Optional[bool]

Whether to automatically answer the call before playing audio.

Returns

Self — The builder instance for method chaining.

Example

1from signalwire import SWMLService, SWMLBuilder
2
3service = SWMLService(name="player")
4builder = SWMLBuilder(service)
5
6# Single audio file
7doc = (
8 builder
9 .answer()
10 .play(url="https://example.com/welcome.mp3")
11 .build()
12)
13print(doc)
14
15# Multiple files in sequence
16builder.reset()
17doc = (
18 builder
19 .answer()
20 .play(urls=[
21 "https://example.com/greeting.mp3",
22 "https://example.com/menu.mp3"
23 ])
24 .build()
25)
26print(doc)
27
28# Text-to-speech via say: prefix
29builder.reset()
30doc = (
31 builder
32 .answer()
33 .play(url="say:Welcome to our service.", say_voice="rime.spore")
34 .build()
35)
36print(doc)