2017 © Pedro Peláez
 

project pronounce-php

Create English pronunciation strings for over 130,000 words. Hyphenate English words.

image

zachleigh/pronounce-php

Create English pronunciation strings for over 130,000 words. Hyphenate English words.

  • Wednesday, July 1, 2015
  • by zachleigh
  • Repository
  • 1 Watchers
  • 5 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Pronounce-PHP

Build Status Latest Stable Version Latest Unstable Version License, (*1)

-Converts words to pronunciation strings using the Carnegie Mellon University Pronouncing Dictionary (CMUdict) file. Currently converts to the International Phonetic Alphabet (IPA) and to an easier to read spelling approximation.
-Hyphenates English words. Hyphenation for IPA and spelling approximation hopefully coming soon. -Outputs to the console, to a file, or to a database, (*2)

Contents

Installation
Usage

Installation

Requirements
PHP 5.3.9 or higher

Linux users can find PHP releases in their distribution repositories. For other operating systems, please visit the php installation guide for instructions., (*3)

composer

Check the composer documentation for installation instructions., (*4)

Install

If requirements are met, you can install the package in two ways., (*5)

Download

Recommended. Download here and run, (*6)

composer install
Through composer
composer require zachleigh/pronounce-php

If you install through composer, the program will be in vendor/zachleigh/pronounce-php, (*7)

Usage

General syntax overview
pronounce-php command [argument]  [options]

Commands

all

Output the entire CMUdict file with arpabet, hyphenation, IPA, and spelling approximation strings to either a file or a database. Default is to write to a file called 'output.txt'., (*8)

Syntax overview
pronounce-php all [options]
Options
--destination [-d]

Set the output destination. Default is to output to a file called 'output.txt'. If file is selected (default), fields will be seperated by a forward slash (/) surrounded by spaces.
Available desitinations: [file, database], (*9)

pronounce-php all --destination=database
--fields [-f]

Set the output fields to be displayed. Fields must be in a comma seperated list. All fields are enabled by default.
Available fields: [word, hyphenated_word, arpabet, ipa, spelling], (*10)

pronounce-php all --fields=word,arpabet,ipa
--file [-o]

If 'file' is selected for the output destination, the 'file' option can be used to set a file name to write to. The default file name is 'output.txt' and is written to the pronounce-php directory., (*11)

pronounce-php all --destination=file --file=my_file.txt
--multiple [-m]

For some words in the CMUdict file, there are multiple pronunciation entries. The file deals with these by appending a number in parentheses to each additional entry., (*12)

ACERO  AH0 S EH1 R OW0
ACERO(1)  AH0 S Y EH1 R OW0
ACERO(2)  AH0 TH EH1 R OW0

The 'multiple' command sets the behavior to deal with thses multiple entries for the output. By default, 'multiple' is set to 'none', which outputs entries exactly as they appear in the CMUdict file. 'repeat' outputs entries without the parentheses or numbers., (*13)

pronounce-php lookup words_to_lookup --multiple=repeat
--symbol [-s]

Set the character to be used for hyphenation. The default value is a hyphen (-). Note: if writing to a file, keep in mind that items in the file will be divided by forward slashes(/) so setting the hyphenation symbol to forward slash will complicate reading of the file., (*14)

pronounce-php all --symbol=.
Examples

Basic usage, (*15)

./pronounce-php all


Lines in file will look like this:
accepting / ac-cept-ing / AE0 K S EH1 P T IH0 NG / æksɛ'ptɪŋ / akse'pting /

Set desired output fields with the 'fields' option., (*16)

./pronounce-php all --fields=word,ipa,spelling


Lines in file will look like this:
accepting / æksɛ'ptɪŋ / akse'pting /

Change the symbol used to divide the hyphenated word with the 'symbol' option., (*17)

./pronounce-php all --symbol=.


Lines in file will look like this:
accepting / ac.cept.ing / AE0 K S EH1 P T IH0 NG / æksɛ'ptɪŋ / akse'pting /

Set the ouput destination with the 'destination' option. Only one destination may be choosen. If 'destination' is set to 'file' (the default value), use the 'file' option to specify a file to write to., (*18)

./pronounce-php all --file=all.txt


Successfully wrote to all.txt

If 'destination' is set to 'database', database credentials will be read from .env and configuration will be read from config.php., (*19)

./pronouncephp all --destination=database


Successfully wrote to database

hyphenate

Hyphenate a word or words. Note that this function is mostly accurate, but there may be some errors. If you find an error, please report it so I can add the word to the exception list., (*20)

Syntax overview
pronounce-php hyphenate words_to_hyphenate [options]
Options
--destination [-d]

Set the output destination. Default is to output a table to the console. If file is selected, fields will be seperated by a forward slash (/) surrounded by spaces.
Available desitinations: [table, string, file, database], (*21)

pronounce-php hyphenate words_to_hyphenate --destination=file
--file [-o]

If 'file' is selected for the output destination, the 'file' option can be used to set a file name to write to. The default file name is 'output.txt' and is written to the pronounce-php directory., (*22)

pronounce-php hyphenate words_to_hyphenate --destination=file --file=my_file.txt
--symbol [-s]

Set the character to be used for hyphenation. The default value is a hyphen (-). Note: if writing to a file, keep in mind that items in the file will be divided by forward slashes(/) so setting the hyphenation symbol to forward slash will complicate reading of the file., (*23)

pronounce-php hyphenate words_to_hyphenate --symbol=/
Examples

Basic usage, (*24)

./pronounce-php hyphenate hello


+-------+-----------------+
| word  | hyphenated_word |
+-------+-----------------+
| hello | hel-lo          |
+-------+-----------------+

A comma seperated list of words may also be given., (*25)

./pronounce-php hyphenate basket,curtain,hyphenate


+-----------+-----------------+
| word      | hyphenated_word |
+-----------+-----------------+
| basket    | bas-ket         |
| curtain   | cur-tain        |
| hyphenate | hy-phen-ate     |
+-----------+-----------------+

Change the symbol used to divide word with the 'symbol' option., (*26)

./pronounce-php hyphenate machine --symbol=.


+---------+-----------------+
| word    | hyphenated_word |
+---------+-----------------+
| machine | ma.chine        |
+---------+-----------------+

Set the ouput destination with the 'destination' option. Only one destination may be choosen. Setting 'destination' to 'string' produces a string instead of a table., (*27)

./pronounce-php hyphenate flower,mountain --destination=string


word: flower hyphenated word: flower 
word: mountain hyphenated_word: moun-tain 

Setting 'destination' to 'file' writes the output to a file. The default file is 'output.txt'., (*28)

./pronounce-php hyphenate cupcakes,headphones --destination=file


Successfully wrote to output.txt

ouput.txt, (*29)

cupcakes / cup-cakes / 
headphones / head-phones / 

If 'destination' is set to 'file', use the 'file' option to specify a file to write to., (*30)

./pronounce-php hyphenate reading,eating,shopping --destination=file --file=hyphen.txt


Successfully wrote to hyphen.txt

hyphen.txt, (*31)

reading / read-ing / 
eating / eat-ing / 
shopping / shop-ping / 

If 'destination' is set to 'database', database credentials will be read from .env and configuration will be read from config.php., (*32)

./pronouncephp hyphenate goodbye --destination=database


Successfully wrote to database

lookup

Look up a word and output the Arpabet, IPA and Spelling approximation pronunciation strings. The lookup command takes one argument: the word or words to be looked up., (*33)

Syntax overview
pronounce-php lookup words_to_lookup [options]
Options
--destination [-d]

Set the output destination. Default is to output a table to the console. If 'file' is selected, fields will be seperated by a forward slash (/) surrounded by spaces.
Available desitinations: [table, string, file, database], (*34)

pronounce-php lookup words_to_lookup --destination=string
--fields [-f]

Set the output fields to be displayed. Fields must be in a comma seperated list. All fields are enabled by default.
Available fields: [word, arpabet, ipa, spelling], (*35)

pronounce-php lookup words_to_lookup --fields=word,arpabet,ipa,spelling
--file [-o]

If 'file' is selected for the output destination, the 'file' option can be used to set a file name to write to. The default file name is 'output.txt' and is written to the pronounce-php directory., (*36)

pronounce-php lookup words_to_lookup --destination=file --file=my_file.txt
--hyphenate [-y]

If the 'hyphenate' flag is given, applicable fields will be hyphenated. Currently, only the 'word' field may be hyphenated., (*37)

pronounce-php lookup words_to_lookup --hyphenate
--multiple [-m]

For some words in the CMUdict file, there are multiple pronunciation entries. The file deals with these by appending a number in parentheses to each additional entry., (*38)

ACERO  AH0 S EH1 R OW0
ACERO(1)  AH0 S Y EH1 R OW0
ACERO(2)  AH0 TH EH1 R OW0

The 'multiple' command sets the behavior to deal with thses multiple entries for the output. By default, 'multiple' is set to 'none', which outputs entries exactly as they appear in the CMUdict file. 'repeat' outputs entries without the parentheses or numbers., (*39)

pronounce-php lookup words_to_lookup --multiple=repeat
--symbol [-s]

Set the character to be used for hyphenation. The default value is a hyphen (-). Note: if writing to a file, keep in mind that items in the file will be divided by forward slashes(/) so setting the hyphenation symbol to forward slash will complicate reading of the file., (*40)

pronounce-php lookup words_to_lookup --symbol=_
Examples

Basic usage, (*41)

./pronounce-php lookup hello


+-------+--------------+--------+----------+
| word  | arpabet      | ipa    | spelling |
+-------+--------------+--------+----------+
| hello | HH AH0 L OW1 | hʌɫoʊ' | huhloh'  |
+-------+--------------+--------+----------+

A comma seperated list of words may also be given. Note that words will be returned in alphabetical order., (*42)

./pronounce-php lookup elephant,zebra,giraffe


+----------+---------------------+----------+------------+
| word     | arpabet             | ipa      | spelling   |
+----------+---------------------+----------+------------+
| elephant | EH1 L AH0 F AH0 N T | ɛ'ɫʌfʌnt | e'luhfuhnt |
| giraffe  | JH ER0 AE1 F        | dʒɝæ'f   | jura'f     |
| zebra    | Z IY1 B R AH0       | zi'brʌ   | zee'bruh   |
+----------+---------------------+----------+------------+

Using the 'hyphenate' flag hyphenates the 'word' field., (*43)

./pronounce-php lookup money,coffee,schedule --hyphenate


+-----------+------------------+----------+----------+
| word      | arpabet          | ipa      | spelling |
+-----------+------------------+----------+----------+
| cof-fee   | K AA1 F IY0      | kɑ'fi    | ko'fee   |
| mon-ey    | M AH1 N IY0      | mʌ'ni    | muh'nee  |
| sched-ule | S K EH1 JH UH0 L | skɛ'dʒʊɫ | ske'juul |
+-----------+------------------+----------+----------+

Use the 'symbol' option to set the character used for hyphenation., (*44)

./pronounce-php lookup monkey,furry --hyphenate --symbol=~


+---------+----------------+--------+-----------+
| word    | arpabet        | ipa    | spelling  |
+---------+----------------+--------+-----------+
| fur~ry  | F ER1 IY0      | fɝ'i   | fur'ee    |
| mon~key | M AH1 NG K IY0 | mʌ'ŋki | muh'ngkee |
+---------+----------------+--------+-----------+

Set desired output fields with the 'fields' option. Fields will be displayed in the order given., (*45)

./pronounce-php lookup blue,red,green --fields=word,ipa


+-------+-------+
| word  | ipa   |
+-------+-------+
| blue  | bɫu'  |
| green | gri'n |
| red   | rɛ'd  |
+-------+-------+

Set the ouput destination with the 'destination' option. Only one destination may be choosen.
Setting 'destination' to 'string' produces a string instead of a table., (*46)

./pronounce-php lookup desk,chair,pencil --destination=string


word: chair arpabet: CH EH1 R ipa: tʃɛ'r spelling: che'r 
word: desk arpabet: D EH1 S K ipa: dɛ'sk spelling: de'sk 
word: pencil arpabet: P EH1 N S AH0 L ipa: pɛ'nsʌɫ spelling: pe'nsuhl 

Setting 'destination' to 'file' writes the output to a file. The default file is 'output.txt'., (*47)

./pronounce-php lookup guitar --destination=file


Successfully wrote to output.txt

ouput.txt, (*48)

guitar / G IH0 T AA1 R / gɪtɑ'r / gito'r /

If 'destination' is set to 'file', use the 'file' option to specify a file to write to., (*49)

./pronounce-php lookup night,day,noon --destination=file --file=words.txt


Successfully wrote to words.txt

words.txt, (*50)

day / D EY1 / deɪ' / dey' / 
night / N AY1 T / naɪ't / nahy't / 
noon / N UW1 N / nu'n / noo'n /

If 'destination' is set to 'database', database credentials will be read from .env and configuration will be read from config.php., (*51)

./pronouncephp lookup goodbye --destination=database


Successfully wrote to database

Database Usage

Requirements

If you wish to fill a database with the information gained from using this program, you must be sure that your database meets the following requirements: * Tables must have an auto-incrementing 'id' column * Column names must exactly match the expected field names. * All command field names: 'word', 'hyphenated_word', 'arpabet', 'ipa', 'spelling' * Hyphenate command field names: 'word', 'hyphenated_word'
* Lookup command field names: 'word', 'arpabet', 'ipa', 'spelling', (*52)

Use the 'field' option to set which fields you wish to insert into your database., (*53)

Setup

First, copy the .env.example file (found in the pronounce-php root folder) to a new file called .env. Open the .env file in a text editor and enter applicable database information., (*54)

Next, open config.php in a text-editor. In the 'database' field, enter in the database type you are using. Currently, only Mysql is supported (see below for information about other database types). If you wish, you can change the charset in the 'connections' field, but the default 'utf8' should satisfy most people. That should be all you have to do. The other information in the file is pulled in from the .env file you setup in the previous step., (*55)

Other database types

The database connection uses php PDO drivers that can be changed out fairly easily. Currently, PDO supports 12 database types. Check the driver list for more information. If you wish to make an adapter for one of these database types, adapter name rules must be followed. * Cuprid: CupridDatabase * FreeTDS / Microsoft SQL Server / Sybase: DblibDatabase * Firebird: FirebirdDatabase * IBM DB2: IbmDatabase * IBM Informix Dynamic Server: InformixDatabase * MySQL: MysqlDatabase * Oracle Call Interface: OciDatabase * ODBC v3 (IBM DB2, unixODBC and win32 ODBC): OdbcDatabase * PostgreSQL: PgsqlDatabase * SQLite 3 and SQLite 2: SqliteDatabase * Microsoft SQL Server / SQL Azure: SqlsrvDatabase * 4d: FourD (A class naming rule exception exists for this, but it is untested), (*56)

The adapter class should be in its own file in src/Database/Databases/ and must implement DatabaseInterface. If you make a new adapter, please let me know so I can include it in the main program. If you dont know how to write a new adapter, let me know and Ill do it if time permits., (*57)

Besides making an adapter, you will also have to make a new array for the database in 'connections' in config.php., (*58)

The Versions

01/07 2015

dev-dev

dev-dev https://github.com/zachleigh/pronounce-php

Create English pronunciation strings for over 130,000 words. Hyphenate English words.

  Sources   Download

MIT

The Requires

 

by Zach Leigh

dictionary english hyphenation spelling ipa hyphenate pronounce arpabet pronunciation cmudict

28/06 2015

dev-master

9999999-dev https://github.com/zachleigh/pronounce-php

Create English pronunciation strings for over 130,000 words. Hyphenate English words.

  Sources   Download

MIT

The Requires

 

by Zach Leigh

dictionary english hyphenation spelling ipa hyphenate pronounce arpabet pronunciation cmudict

28/06 2015

0.8

0.8.0.0 https://github.com/zachleigh/pronounce-php

Create English pronunciation strings for over 130,000 words. Hyphenate English words.

  Sources   Download

GPL-2.0

The Requires

 

by Zach Leigh

dictionary english hyphenation spelling ipa hyphenate pronounce arpabet pronunciation cmudict

26/06 2015

0.7

0.7.0.0 https://github.com/zachleigh/pronounce-php

Create English pronunciation strings for over 130,000 words. Hyphenate English words.

  Sources   Download

GPL-2.0

The Requires

 

by Zach Leigh

dictionary english hyphenation spelling ipa hyphenate pronounce arpabet pronunciation cmudict

25/06 2015

0.6

0.6.0.0 https://github.com/zachleigh/pronounce-php

Create English pronunciation strings for over 130,000 words. Hyphenate English words.

  Sources   Download

GPL-2.0

The Requires

 

by Zach Leigh

dictionary english hyphenation spelling ipa hyphenate pronounce arpabet pronunciation cmudict

24/06 2015

0.5

0.5.0.0 https://github.com/zachleigh/pronounce-php

Create English pronunciation strings for over 130,000 words. Hyphenate English words.

  Sources   Download

GPL-2.0

The Requires

 

by Zach Leigh

dictionary english hyphenation spelling ipa pronounce arpabet pronunciation cmudict