3 > module Main(main) where
5 >#ifndef __GLASGOW_HASKELL__
7 > import Maybe -- an hbc library module defining the ``Maybe'' type
10 > import Native -- an hbc library module for native-mode binary IO
12 > import LPA -- the linear predictive analysis module
15 > main = getContents >>= \bs ->
18 > main = readChan stdin exit $ \bs ->
19 > appendChan stdout (program bs) exit done
21 > {- ORIGINAL: partain:
22 > main = getArgs exit $ \args ->
24 > [file1, file2] -> readFile file1 exit $ \bs ->
25 > writeFile file2 (program bs) exit done
29 > usage = "usage: lpa <speech file> <output file>"
32 > window_width = 384 :: Int -- 24 ms @ 16 kHz
33 > window_offset = 160 :: Int -- 10 ms @ 16 kHz
34 > p = 14 :: Int -- LP analysis order
35 > q = 16 :: Int -- cepstral analysis order
38 > readRawSpeech :: Bytes -> Signal Int
40 > case bytesToShortInt bs of
41 > Nothing -> if null bs then [] else error read_error
42 > Just (v,bs') -> v : readRawSpeech bs'
44 > read_error = "Left-over byte encountered by readRawSpeech"
47 > castSignal :: Signal Int -> Signal Float
48 > castSignal = map fromInt
51 > program :: Bytes -> String
54 > = let signal = readRawSpeech bs in
55 > -- trace (shows (take 200 signal) "\n\n") (
56 > ((foldr writesFrame []
58 > . windows window_width window_offset
60 > . castSignal) signal)
64 > program = foldr writesFrame []
66 > . windows window_width window_offset
73 It only remains to define a function for writing the analysis
77 > writesFrame :: (Float, [Float]) -> Bytes -> Bytes
78 > writesFrame (log_energy, cep) bs =
79 > showBytes log_energy (listShowBytes cep bs)