Skip to navigation

say_digits

View as MarkdownOpen in Claude

Return the digits in text, one word each, as a voice should read a ZIP code, an account number, or a phone number. Anything that isn’t a digit separates groups, and a comma between groups makes the voice pause.

from signalwire.speech import say_digits

Parameters

text
str | intRequired

The digits, with any separators.

group
int | Sequence[int] | NoneDefaults to None

How to group the digits.

  • None — keep the groups text already has, split at anything that isn’t a digit.
  • An int — split the digits into groups of that size.
  • A sequence of sizes — split the digits into those sizes, in order, with any remaining digits in a last group.

Raises ValueError for a size below 1.

zero
strDefaults to zero

Keyword-only. The word for 0, such as "oh".

Returns

str — The words, with groups separated by ", ", or "" when text has no digits.

Example

from signalwire.speech import say_digits
print(say_digits("415-555-0192"))
# four one five, five five five, zero one nine two
print(say_digits("10001", zero="oh"))
# one oh oh oh one
print(say_digits("18005550199", group=(1, 3, 3)))
# one, eight zero zero, five five five, zero one nine nine

Part of the speech helpers module.