diff --git a/includes/class-twp-webhooks.php b/includes/class-twp-webhooks.php index ea085b1..e94b45e 100644 --- a/includes/class-twp-webhooks.php +++ b/includes/class-twp-webhooks.php @@ -2975,17 +2975,32 @@ class TWP_Webhooks { } /** - * Format phone number for speech (adds pauses between digits) + * Format phone number for speech (reads each digit individually) */ private function format_phone_number_for_speech($number) { - // Remove +1 country code and format for speech + // Remove +1 country code and any formatting $cleaned = preg_replace('/^\+1/', '', $number); + $cleaned = preg_replace('/[^0-9]/', '', $cleaned); if (strlen($cleaned) == 10) { - // Format as (xxx) xxx-xxxx with pauses - return substr($cleaned, 0, 3) . ' ' . substr($cleaned, 3, 3) . ' ' . substr($cleaned, 6, 4); + // Break into individual digits with pauses for natural speech + // Area code: 9-0-9, Main number: 5-7-3-7-3-7-2 + $area_code = str_split(substr($cleaned, 0, 3)); + $exchange = str_split(substr($cleaned, 3, 3)); + $number_part = str_split(substr($cleaned, 6, 4)); + + // Join with spaces so TTS reads each digit individually + return implode(' ', $area_code) . ', ' . implode(' ', $exchange) . ', ' . implode(' ', $number_part); + } elseif (strlen($cleaned) == 11 && substr($cleaned, 0, 1) == '1') { + // Handle numbers that still have the 1 prefix + $area_code = str_split(substr($cleaned, 1, 3)); + $exchange = str_split(substr($cleaned, 4, 3)); + $number_part = str_split(substr($cleaned, 7, 4)); + + return implode(' ', $area_code) . ', ' . implode(' ', $exchange) . ', ' . implode(' ', $number_part); } - return $number; + // Fallback: just break into individual digits + return implode(' ', str_split($cleaned)); } } \ No newline at end of file