3 > module Main(main) where
5 >#ifndef __GLASGOW_HASKELL__
7 > import Maybe -- an hbc library module defining the ``Maybe'' type
9 > import Int( Num(fromInt) )
11 > import Native -- an hbc library module for native-mode binary IO
13 > import LPA -- the linear predictive analysis module
16 > main = getContents >>= \bs ->
19 > main = readChan stdin exit $ \bs ->
20 > appendChan stdout (program bs) exit done
22 > {- ORIGINAL: partain:
23 > main = getArgs exit $ \args ->
25 > [file1, file2] -> readFile file1 exit $ \bs ->
26 > writeFile file2 (program bs) exit done
30 > usage = "usage: lpa <speech file> <output file>"
33 > window_width = 384 :: Int -- 24 ms @ 16 kHz
34 > window_offset = 160 :: Int -- 10 ms @ 16 kHz
35 > p = 14 :: Int -- LP analysis order
36 > q = 16 :: Int -- cepstral analysis order
39 > readRawSpeech :: Bytes -> Signal Int
41 > case bytesToShortInt bs of
42 > Nothing -> if null bs then [] else error read_error
43 > Just (v,bs') -> v : readRawSpeech bs'
45 > read_error = "Left-over byte encountered by readRawSpeech"
48 > castSignal :: Signal Int -> Signal Float
49 > castSignal = map fromInt
52 > program :: Bytes -> String
55 > = let signal = readRawSpeech bs in
56 > -- trace (shows (take 200 signal) "\n\n") (
57 > ((foldr writesFrame []
59 > . windows window_width window_offset
61 > . castSignal) signal)
65 > program = foldr writesFrame []
67 > . windows window_width window_offset
74 It only remains to define a function for writing the analysis
78 > writesFrame :: (Float, [Float]) -> Bytes -> Bytes
79 > writesFrame (log_energy, cep) bs =
80 > showBytes log_energy (listShowBytes cep bs)