1
0
forked from GitHub/gf-core

Added semi-working speech_input command.

This commit is contained in:
bringert
2005-12-13 21:03:56 +00:00
parent 0101410954
commit 18a57aa56a
15 changed files with 190 additions and 11 deletions

View File

@@ -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

View File

@@ -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"

View File

@@ -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