Page 1 of 1

Text to Phonemes / C to PB converter

Posted: Tue May 05, 2009 4:48 pm
by wmorton
Hi, is there any source for a text to phoneme converter in PB? Failing this, is there a C to PB converter? I found something but it's in C (and I don't know the first thing about C) http://www.speech.cs.cmu.edu/comp.speec ... eme.3.html

Thanks!

Posted: Tue May 05, 2009 4:58 pm
by Tomi
maybe "Demo_Sapi.pb" sample in COMate 4.30 by srod in http://www.nxsoftware.com/ :)

Posted: Tue May 05, 2009 5:06 pm
by wmorton
Ah yes, I've just had a look at this, it sends text to a SAPI voice.

What I am looking for though, is something like the program in my first post, where it converts text to phonemes, not text to speech. So, if I type in "My Generation." the program outputs "~mAY _J2EHnAXr1EYSIXn." (or similar)

Thanks!

Posted: Tue May 05, 2009 5:15 pm
by dagcrack
If you decide to port the code, do try and don't give up. You'll soon realize the syntax of C isn't that hard and you'll probably even have an epiphany sooner or later.

Just to get you started the first 3 functions of phoneme.c

Code: Select all

Procedure.i isupper( chr.c )
	ProcedureReturn ( chr => 'A' And chr <= 'Z' )
EndProcedure

Procedure.i isvowel( chr.c )
	ProcedureReturn ( chr = 'A' Or chr = 'E' Or chr = 'I' Or chr = 'O' Or chr = 'U' )
EndProcedure

Procedure.i isconsonant( chr.c )
	ProcedureReturn ( isupper(chr) And Not isvowel(chr) )
EndProcedure
One of the biggest problems will probably be the arrays due to syntax constraints in PB but you could easily load the contents from a txt which will ultimately be a better option if you require flexibility, although the data appears to be constant in this case.

Some functions are not required to be ported because in PB you already have quite a few string manipulation helpers. Unless that is you want to perform a literal port of the code.

In such case you'll need this as well:

Code: Select all

Procedure.i isalpha( chr.c )
	ProcedureReturn (chr => 'A' And chr <= 'Z') Or (chr => 'a' And chr <= 'z')
EndProcedure

Procedure.i isdigit( chr.c )
	ProcedureReturn (chr => '0' And chr <= '9')
EndProcedure

Procedure.i islower( chr.c )
	ProcedureReturn (chr => 'a' And chr <= 'z')
EndProcedure
some testing code...

Code: Select all

Debug isupper( 'a' )
Debug isupper( 'A' )

Debug isvowel( 'F' )
Debug isvowel( 'E' )

Debug isconsonant( 'A' )
Debug isconsonant( 'D' )


Debug isalpha('0')
Debug isalpha('A')

Debug isdigit( 'D' )
Debug isdigit( '4' )

Debug islower( 'A' )
Debug islower( 'a' )

Cheers.