en_phoneme.pl 606 B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/perl
  2. # Author: Trizen
  3. # License: GPLv3
  4. # Date: 15 April 2014
  5. # Website: https://github.com/trizen
  6. # usage: ./en_phoneme.pl [word] [word] [...]
  7. use 5.010;
  8. use strict;
  9. use warnings;
  10. use Lingua::EN::Phoneme;
  11. my $lep = Lingua::EN::Phoneme->new;
  12. sub normalize {
  13. my $syl = lc($_[0]);
  14. $syl =~ s/h0\z/x/;
  15. $syl =~ s/\w\K0\z//;
  16. $syl =~ s/\w\K1\z//;
  17. return $syl;
  18. }
  19. foreach my $word (@ARGV) {
  20. my $p_word = $lep->phoneme($word) // do {
  21. warn "error: '$word' is not an English word!\n";
  22. next;
  23. };
  24. say join(" ", map { normalize($_) } split(' ', $p_word));
  25. }