Skip to content

Commit

Permalink
preserve <phoneme> tag as a tag
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRDOrazio committed Oct 17, 2024
1 parent 48a1e63 commit b92737e
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/LiturgyOfTheDay.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class LiturgyOfTheDay
private \IntlDateFormatter $monthDayFmt;
private array $queryParams = [];
private const PHONETIC_PRONUNCATION_MAPPING = [
'/Blessed( Virgin Mary)/' => '<phoneme alphabet="ipa" ph="ˈblɛsɪd">Blessed</phoneme>$1',
'/Antiochia/' => '<phoneme alphabet="ipa" ph="ɑntɪˈokiɑ">Antiochia</phoneme>',
'/Blessed /' => '<phoneme alphabet="ipa" ph="ˈblɛsɪd">Blessed</phoneme> ',
'/Antiochia/' => '<phoneme alphabet="ipa" ph="ɑntɪˈokiɑ">Antiochia</phoneme>',
];

/**
Expand Down Expand Up @@ -373,7 +373,7 @@ private function prepareMainText(Festivity $festivity, int $idx): array
// Create the <speak> root element
$speak = new \SimpleXMLElement('<speak></speak>');
$voice = $speak->addChild('voice');
$lang = $voice->addChild('lang');
$lang = $voice->addChild('lang', $mainText);
$namespaces = [
'xml' => 'http://www.w3.org/XML/1998/namespace'
];
Expand Down Expand Up @@ -417,22 +417,21 @@ private function prepareMainText(Festivity $festivity, int $idx): array
break;
}

//Fix some phonetic pronunciations
foreach (LiturgyOfTheDay::PHONETIC_PRONUNCATION_MAPPING as $key => $value) {
if (preg_match($key, $mainText) === 1) {
$ssml = preg_replace($key, $value, $mainText);
}
}

$lang[0] = $ssml !== null ? $ssml : $mainText;

// Convert SimpleXMLElement to DOMDocument
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = false;
$dom->loadXML($speak->asXML());
$ssml = $dom->saveXML($dom->documentElement);

//Fix some phonetic pronunciations
foreach (LiturgyOfTheDay::PHONETIC_PRONUNCATION_MAPPING as $key => $value) {
if (preg_match($key, $mainText) === 1) {
$ssml = preg_replace($key, $value, $ssml);
}
}
}
return ["mainText" => $mainText, "ssml" => $dom->saveXML($dom->documentElement)];
return ["mainText" => $mainText, "ssml" => $ssml];
}

/**
Expand Down

0 comments on commit b92737e

Please sign in to comment.