diff options
| author | bringert <bringert@cs.chalmers.se> | 2005-12-13 21:03:56 +0000 |
|---|---|---|
| committer | bringert <bringert@cs.chalmers.se> | 2005-12-13 21:03:56 +0000 |
| commit | 5a480fac520db1bab6f1336bee9b2031dbd36cab (patch) | |
| tree | 01210f87844268c0652867df51f4831094fa3e17 /src/GF/System | |
| parent | 9f867c4922cccb6e61b273a55103e2afaeac4bde (diff) | |
Added semi-working speech_input command.
Diffstat (limited to 'src/GF/System')
| -rw-r--r-- | src/GF/System/ATKSpeechInput.hs | 65 | ||||
| -rw-r--r-- | src/GF/System/NoSpeechInput.hs | 17 | ||||
| -rw-r--r-- | src/GF/System/SpeechInput.hs | 27 |
3 files changed, 109 insertions, 0 deletions
diff --git a/src/GF/System/ATKSpeechInput.hs b/src/GF/System/ATKSpeechInput.hs new file mode 100644 index 000000000..8c0ed303e --- /dev/null +++ b/src/GF/System/ATKSpeechInput.hs @@ -0,0 +1,65 @@ +---------------------------------------------------------------------- +-- | +-- Module : GF.System.ATKSpeechInput +-- Maintainer : BB +-- Stability : (stable) +-- Portability : (non-portable) +-- +-- > CVS $Date: 2005/05/10 15:04:01 $ +-- > CVS $Author: bringert $ +-- > CVS $Revision: 1.2 $ +-- +-- Use ATK and Speech.ATKRec for speech input. +----------------------------------------------------------------------------- + +module GF.System.ATKSpeechInput (recognizeSpeech) where + +import GF.Infra.Ident (Ident, prIdent) +import GF.Infra.Option (Options) +import GF.Conversion.Types (CGrammar) +import GF.Speech.PrSLF + +import Speech.ATKRec + +import Control.Monad +import Data.IORef +import System.IO +import System.IO.Unsafe + +-- FIXME: get these from somewhere else + +config = "/home/bjorn/projects/atkrec/atkrec.cfg" + +res = "/home/bjorn/src/atk/Resources" +hmmlist = res ++ "/UK_SI_ZMFCC/hmmlistbg" +mmf0 = res ++ "/UK_SI_ZMFCC/WI4" +mmf1 = res ++ "/UK_SI_ZMFCC/BGHMM2" +dict = res ++ "/beep.dct" + +initialized :: IORef Bool +initialized = unsafePerformIO $ newIORef False + +initATK :: IO () +initATK = do + b <- readIORef initialized + when (not b) $ do + hPutStrLn stderr "Initializing..." + initialize config + loadHMMSet "hmm_english" hmmlist mmf0 mmf1 + loadDict "dict_english" dict + writeIORef initialized True + +recognizeSpeech :: Ident -- ^ Grammar name + -> Options -> CGrammar -> IO String +recognizeSpeech name opts cfg = + do + let slf = slfPrinter name opts cfg + n = prIdent name + slfName = "gram_" ++ n + recName = "rec_english_" ++ n + initATK + loadGrammarString slfName slf + createRecognizer recName "hmm_english" "dict_english" slfName + hPutStrLn stderr "Listening..." + s <- recognize recName + return s diff --git a/src/GF/System/NoSpeechInput.hs b/src/GF/System/NoSpeechInput.hs new file mode 100644 index 000000000..2f967f66f --- /dev/null +++ b/src/GF/System/NoSpeechInput.hs @@ -0,0 +1,17 @@ +---------------------------------------------------------------------- +-- | +-- Module : GF.System.NoSpeechInput +-- Maintainer : BB +-- Stability : (stable) +-- Portability : (portable) +-- +-- > CVS $Date: 2005/05/10 15:04:01 $ +-- > CVS $Author: bringert $ +-- > CVS $Revision: 1.2 $ +-- +-- Dummy speech input. +----------------------------------------------------------------------------- + +module GF.System.NoSpeechInput (recognizeSpeech) where + +recognizeSpeech = fail "No speech input available" diff --git a/src/GF/System/SpeechInput.hs b/src/GF/System/SpeechInput.hs new file mode 100644 index 000000000..6c2374473 --- /dev/null +++ b/src/GF/System/SpeechInput.hs @@ -0,0 +1,27 @@ +{-# OPTIONS -cpp #-} + +---------------------------------------------------------------------- +-- | +-- Module : GF.System.SpeechInput +-- Maintainer : BB +-- Stability : (stable) +-- Portability : (portable) +-- +-- > CVS $Date: 2005/05/10 15:04:01 $ +-- > CVS $Author: bringert $ +-- > CVS $Revision: 1.2 $ +-- +-- Uses the right speech recognition library for speech input. +----------------------------------------------------------------------------- + +module GF.System.SpeechInput (recognizeSpeech) where + +#ifdef USE_ATK + +import GF.System.ATKSpeechInput (recognizeSpeech) + +#else + +import GF.System.NoSpeechInput (recognizeSpeech) + +#endif |
