wikimedia / ipa-validator
用于验证和标准化IPA的Composer包
v1.1.1
2022-11-17 17:53 UTC
Requires
- php: >=7.4
Requires (Dev)
README
基本用法
// Load composer's autoloader require_once __DIR__ . '/vendor/autoload.php'; // Load the validator use Wikimedia\IPAValidator\Validator; /* * Create a new validator with the options: * - Remove delimiters (defaults to true) * - Normalize IPA (defaults to false) * - Normalize to Google TTS standard (defaults to false) */ $validator = new Validator( '/pʰə̥ˈkj̊uːliɚ/', true, true, true ); // Check if the IPA is valid echo $validator->valid; # true // Get the normalized IPA echo $validator->normalizedIPA; # phəˈkjuːliɚ // Get the original IPA echo $validator->originalIPA; # /pʰə̥ˈkj̊uːliɚ/
选项
当构建新的Validator
时,您可以设置以下选项
/** * Constructor * * @param string $ipa IPA to validate * @param bool $strip Remove delimiters * @param bool $normalize Normalize IPA * @param bool $google Normalize IPA for Google TTS */ public function __construct( $ipa, $strip = true, $normalize = false, $google = false )
移除分隔符
此选项将从IPA中移除一些分隔符——目前是/.../
和[...]
标准化IPA
当$google
为false
时,此选项将标准化IPA并移除常见的错误Unicode字符(例如,在单词tenoːt͡ʃˈtit͡ɬan
中使用:
代替ː
)。
为Google TTS标准化IPA
作为一项工作项目的一部分,我们正在向Google的TTS引擎提供IPA——Google对诸如重音符号等事物有一些看法。例如,IPA ˈɔːfɫ̩
在Google TTS中无法正确显示。使用自定义charmap来标准化某些字符。
$charmap = [ [ '(', '' ], [ ')', '' ], // 207F [ 'ⁿ', 'n' ], // 02B0 [ 'ʰ', 'h' ], // 026B [ 'ɫ', 'l' ], // 02E1 [ 'ˡ', 'l' ], // 02B2 [ 'ʲ', 'j' ], ];
将$google
设置为true
也会从IPA字符串中移除所有重音符号。
正则表达式
^[().a-z|æçðøħŋœǀ-ǃɐ-ɻɽɾʀ-ʄʈ-ʒʔʕʘʙʛ-ʝʟʡʢʰʲʷʼˀˈˌːˑ˞ˠˡˤ-˩̴̘̙̜̝̞̟̠̤̥̩̪̬̯̰̹̺̻̼̀́̂̃̄̆̈̊̋̌̏̽̚͜͡βθχ᷄᷅᷈‖‿ⁿⱱ]+$
如果您认为可以改进它,我还在https://regex101.com/r/f2Qhuk上放置了它... (请这么做!)