-- |
-- Module : EspeakNG_IPA
-- Copyright : (c) OleksandrZhabenko 2021
-- License : MIT
-- Stability : Experimental
-- Maintainer : olexandr543@yahoo.com
--
-- Is intended to use internally \"espeak-ng\" or \"espeak\" executable to produce the IPA phonemes output
-- of the given 'String'.
-- The prerequisite is installed espeak-ng or espeak executable in the path that is in the PATH
-- environment variable.
module EspeakNG_IPA where
import System.Process (readProcessWithExitCode)
import EndOfExe (showE)
import System.Exit (ExitCode(..))
import Data.Maybe (fromJust)
{-| Given a language 'String' supported by the espeak-ng or espeak (which one is installed properly) and the
needed text returns the IPA representation. Is just some wrapper around the espeak functionality. -}
espeakNG_IPA :: String -> String -> IO String
espeakNG_IPA lang xs =
case showE "espeak-ng" of
Just path -> readProcessWithExitCode path ("-xq":"--ipa":"-l":[lang]) xs >>=
\(hcode,hout,herr) -> case hcode of
ExitSuccess -> return (unwords . lines $ hout)
_ -> error ("EspeakNG_IPA.espeakNG_IPA: " ++ show herr)
_ -> case showE "espeak" of
Just path2 -> readProcessWithExitCode path2 ("-xq":"--ipa":"-l":[lang]) xs >>=
\(hcode,hout,herr) -> case hcode of
ExitSuccess -> return (unwords . lines $ hout)
_ -> error ("EspeakNG_IPA.espeakNG_IPA: " ++ show herr)
_ -> error ("EspeakNG_IPA.espeakNG_IPA: No espeak or espeak-ng executable is installed in the PATH directories. ")
{-| Given a language 'String' supported by the espeak-ng or espeak (which one is installed properly) and the
needed text prints the IPA representation. Is just some wrapper around the espeak functionality. -}
espeakNG_IPA_ :: String -> String -> IO ()
espeakNG_IPA_ lang xs =
case showE "espeak-ng" of
Just path -> readProcessWithExitCode path ("-xq":"--ipa":"-l":[lang]) xs >>=
\(hcode,hout,herr) -> case hcode of
ExitSuccess -> putStrLn (unwords . lines $ hout)
_ -> error ("EspeakNG_IPA.espeakNG_IPA_: " ++ show herr)
_ -> case showE "espeak" of
Just path2 -> readProcessWithExitCode path2 ("-xq":"--ipa":"-l":[lang]) xs >>=
\(hcode,hout,herr) -> case hcode of
ExitSuccess -> putStrLn (unwords . lines $ hout)
_ -> error ("EspeakNG_IPA.espeakNG_IPA_: " ++ show herr)
_ -> error ("EspeakNG_IPA.espeakNG_IPA_: No espeak or espeak-ng executable is installed in the PATH directories. ")