packages feed

mmsyn7h 0.2.0.0 → 0.2.1.0

raw patch · 5 files changed

+126/−98 lines, 5 filesdep ~mmsyn6ukr

Dependency ranges changed: mmsyn6ukr

Files

ChangeLog.md view
@@ -7,3 +7,7 @@ ## 0.2.0.0 -- 2019-12-25  * Second version. Changed the behaviour of the program.++## 0.2.1.0 -- 2019-12-25++* Second version revised A. Program now is a library and a executable, it has another module structure. Some minor documentation improvements.
+ MMSyn7h.hs view
@@ -0,0 +1,104 @@+-- |+-- Module      :  MMSyn7h+-- Copyright   :  (c) OleksandrZhabenko 2019+-- License     :  MIT+--+-- Maintainer  :  olexandr543@yahoo.com+--+-- An additional program that is used with the mmsyn7ukr executable as a sound creator with the voice+-- given by the files in the current directory. It is very similar to the Main.hs of the mmsyn6ukr package.++--++module MMSyn7h where++import Data.Char (isSpace, isControl)+import Data.Maybe (isJust,fromJust)+import System.IO+import System.Environment (getArgs)+import System.Process (readProcessWithExitCode)+import System.Directory (removeFile, listDirectory)+import Control.Exception (bracketOnError)+import EndOfExe (showE)+import Melodics.Ukrainian (convertToProperUkrainian, takeData)+import UkrainianLControl+import qualified Data.Vector as V+import qualified Data.ByteString.Lazy as B+import Data.List (isSuffixOf)+import CaseBi (getBFst')++-- | Function that proposes and creates if accepted the sound record with the new \"voice\". Besides it can play the newly created file once. It is used in the+-- 'createAndPlayFs' function internally and recursively.+main7h :: IO ()+main7h = bracketOnError (do+  putStrLn "Please, specify the arguments to control the output speech file! "+  putStrLn "See https://hackage.haskell.org/package/mmsyn6ukr-0.6.2.0/docs/UkrainianLControl.html#v:genControl for more information."+  putStrLn "You can specify e. g. \"o9-1\" or \"o5-1\" or other option."+  arg <- getArgs+  let args = take 1 arg in do +    putStrLn "Please, specify the name of the resulting sound file! Please, do NOT use '}' character and space or control characters!"+    nameOfSoundFile <- getLine+    let nameSF = filter (\x -> not (isSpace x) && not (isControl x) && x /= '}') nameOfSoundFile in+      return (args, nameSF)) (\(args, nameSF) -> do+        putStr "Notice, there was (may be) CmdLineArgument exception. To avoid it, please, specify the command line argument (if needed) in the form \"ABC\""+        putStrLn $ " where A is either a letter \'f\', \'o\', \'w\' or a digit and B and C are both digits! The exception (may be) arose from the command line arguments " +          ++ show args ++ " for the file: " ++ show nameSF ++ ". Please, check also whether the SoX was installed with the support for needed codec.") (\(args, nameSF) -> do +            putStrLn ""+            putStr "The resulting file will be played just after it is created by the program. To remove all the created sound files from the directory, "+            putStrLn "please, specify as the first character in the input as \"0\". Otherwise, the program will not remove any records (if they are not overwritten). "+            putStrLn ""+            putStrLn "Now enter the Ukrainian text."+            putStrLn ""+            xs <- getContents+            if take 1 xs == "0" then do+              let ys = take (nSymbols (let zs = take 1 args in if null zs then [] else fst . genControl . head $ zs)) (drop 1 xs) in +                withBinaryFile (nameSF ++ ".raw") AppendMode (appendS16LEFile (convertToProperUkrainian ys))+              putStrLn "The .raw file was created by the program. It will be processed further. "+              let ts = fromJust (showE "sox") in do+                _ <- readProcessWithExitCode ts ["-r22050","-c1","-L","-esigned-integer","-b16", nameSF ++ ".raw", +                       fst . snd . genControl . concat $ args, nameSF ++ (snd . snd . genControl . concat $ args)] ""+                removeFile $ nameSF ++ ".raw"+                if isJust . showE $ "play"+                  then do +                    _ <- readProcessWithExitCode (fromJust . showE $ "play") [nameSF ++ (snd . snd . genControl . concat $ args)] ""+                    cleanCreatedSoundFs+                  else error "SoX play is not installed properly in the system. Please, install it properly and execute the program again."+            else do+              let ys = take (nSymbols (let zs = take 1 args in if null zs then [] else fst . genControl . head $ zs)) xs in +                withBinaryFile (nameSF ++ ".raw") AppendMode (appendS16LEFile (convertToProperUkrainian ys))+              putStrLn "The .raw file was created by the program. It will be processed further. "+              let ts = fromJust (showE "sox") in do+                _ <- readProcessWithExitCode ts ["-r22050","-c1","-L","-esigned-integer","-b16", nameSF ++ ".raw", +                       fst . snd . genControl . concat $ args, nameSF ++ (snd . snd . genControl . concat $ args)] ""+                removeFile $ nameSF ++ ".raw")++-- | The function that actually produces a .raw file. The mapping table is given in the @Map.txt@ file, but the sound duration differs.+appendS16LEFile ::  V.Vector String -> Handle -> IO ()+appendS16LEFile xs hdl | not (V.null xs) = +  do+    dataList <- (V.mapM takeData . V.fromList) ["-.wav", "0.wav", "1.wav", "A.wav", "B.wav", "C.wav", "D.wav", "E.wav", "F.wav", "G.wav", "H.wav", +        "I.wav", "J.wav", "K.wav", "L.wav", "M.wav", "N.wav", "O.wav", "P.wav", "Q.wav", "R.wav", +          "S.wav", "T.wav", "U.wav", "V.wav", "W.wav", "X.wav", "Y.wav", "Z.wav", "a.wav", "b.wav", "c.wav", +            "d.wav", "e.wav", "f.wav"]+    V.mapM_ (\u -> +      if V.all (\z -> B.length z > 0) dataList +        then let rs =  tail . dropWhile (/= ' ') . takeWhile (/= '}') . show $ hdl in do+          hClose hdl+          closedHdl <- hIsClosed hdl+          if closedHdl +            then B.appendFile rs $ dataList V.! getBFst' (0, V.fromList [("-", 0), ("0", 1), ("1", 2), ("а", 3), ("б", 4), +                     ("в", 5), ("г", 6), ("д", 7), ("дж", 8), ("дз", 9), ("е", 10), ("ж", 11), ("з", 12), ("и", 13), +                        ("й", 14), ("к", 15), ("л", 16), ("м", 17), ("н", 18), ("о", 19), ("п", 20), ("р", 21), +                          ("с", 22), ("сь", 23), ("т", 24), ("у", 25), ("ф", 26), ("х", 27), ("ц", 28), ("ць", 29), ("ч", 30), +                            ("ш", 31), ("ь", 32), ("і", 33), ("ґ", 34)]) u+            else error "File is not closed!"+        else error "Data sound file is not read!") xs+    hClose hdl+                       | otherwise = return ()++-- | Function that removes all the sounds with ".raw", ".wav", ".ogg", ".flac" extensions in the current directory. It is used for +-- the security reasons.+cleanCreatedSoundFs :: IO ()+cleanCreatedSoundFs = do+  dirCs <- listDirectory "."+  let remFs = concatMap (\ys -> filter (\zs -> ys `isSuffixOf` zs) dirCs) [".raw", ".wav", ".ogg", ".flac"] in mapM_ removeFile remFs
Main.hs view
@@ -5,28 +5,14 @@ -- -- Maintainer  :  olexandr543@yahoo.com ----- An additional program that is used internally in the mmsyn7ukr package as a sound creator with the voice+-- An additional program that is used with the mmsyn7ukr executable as a sound creator with the voice -- given by the files in the current directory. It is very similar to the Main.hs of the mmsyn6ukr package.  --  module Main where -import Control.Monad (void)-import Data.Char (isSpace, isControl)-import Data.Maybe (isJust,fromJust)-import System.IO-import System.Environment (getArgs)-import System.Process (readProcessWithExitCode)-import System.Directory (removeFile, listDirectory)-import Control.Exception (bracketOnError)-import EndOfExe (showE)-import Melodics.Ukrainian (convertToProperUkrainian, takeData)-import UkrainianLControl-import qualified Data.Vector as V-import qualified Data.ByteString.Lazy as B-import Data.List (isSuffixOf)-import CaseBi (getBFst')+import MMSyn7h   {- -- Inspired by: https://mail.haskell.org/pipermail/beginners/2011-October/008649.html@@ -38,79 +24,3 @@   putStrLn "Next file can be now voiced by your \"voice\"."   main7h --- | Function that proposes and creates if accepted the sound record with the new \"voice\". Besides it can play the newly created file once. It is used in the--- 'createAndPlayFs' function internally and recursively.-main7h :: IO ()-main7h = bracketOnError (do-  putStrLn "Please, specify the arguments to control the output speech file! "-  putStrLn "See https://hackage.haskell.org/package/mmsyn6ukr-0.6.1.0/docs/UkrainianLControl.html#v:genControl for more information."-  putStrLn "You can specify e. g. \"o9-1\" or \"o5-1\" or other option."-  arg <- getArgs-  let args = take 1 arg in do -    putStrLn "Please, specify the name of the resulting sound file! Please, do NOT use '}' character and space or control characters!"-    nameOfSoundFile <- getLine-    let nameSF = filter (\x -> not (isSpace x) && not (isControl x) && x /= '}') nameOfSoundFile in-      return (args, nameSF)) (\(args, nameSF) -> do-        putStr "Notice, there was (may be) CmdLineArgument exception. To avoid it, please, specify the command line argument (if needed) in the form \"ABC\""-        putStrLn $ " where A is either a letter \'f\', \'o\', \'w\' or a digit and B and C are both digits! The exception (may be) arose from the command line arguments " -          ++ show args ++ " for the file: " ++ show nameSF ++ ". Please, check also whether the SoX was installed with the support for needed codec.") (\(args, nameSF) -> do -            putStrLn ""-            putStr "The resulting file will be played just after it is created by the program. To remove all the created sound files from the directory, "-            putStrLn "please, specify as the first character in the input as \"0\". Otherwise, the program will not remove any records (if they are not overwritten). "-            putStrLn ""-            putStrLn "Now enter the Ukrainian text."-            putStrLn ""-            xs <- getContents-            if take 1 xs == "0" then do-              let ys = take (nSymbols (let zs = take 1 args in if null zs then [] else fst . genControl . head $ zs)) (drop 1 xs) in -                withBinaryFile (nameSF ++ ".raw") AppendMode (appendS16LEFile (convertToProperUkrainian ys))-              putStrLn "The .raw file was created by the program. It will be processed further. "-              let ts = fromJust (showE "sox") in do-                _ <- readProcessWithExitCode ts ["-r22050","-c1","-L","-esigned-integer","-b16", nameSF ++ ".raw", -                       fst . snd . genControl . concat $ args, nameSF ++ (snd . snd . genControl . concat $ args)] ""-                removeFile $ nameSF ++ ".raw"-                if isJust . showE $ "play"-                  then do -                    _ <- readProcessWithExitCode (fromJust . showE $ "play") [nameSF ++ (snd . snd . genControl . concat $ args)] ""-                    cleanCreatedSoundFs-                  else error "SoX play is not installed properly in the system. Please, install it properly and execute the program again."-            else do-              let ys = take (nSymbols (let zs = take 1 args in if null zs then [] else fst . genControl . head $ zs)) xs in -                withBinaryFile (nameSF ++ ".raw") AppendMode (appendS16LEFile (convertToProperUkrainian ys))-              putStrLn "The .raw file was created by the program. It will be processed further. "-              let ts = fromJust (showE "sox") in do-                _ <- readProcessWithExitCode ts ["-r22050","-c1","-L","-esigned-integer","-b16", nameSF ++ ".raw", -                       fst . snd . genControl . concat $ args, nameSF ++ (snd . snd . genControl . concat $ args)] ""-                removeFile $ nameSF ++ ".raw")-                ---- | The function that actually produces a .raw file. The mapping table is given in the @Map.txt@ file, but the sound duration differs.-appendS16LEFile ::  V.Vector String -> Handle -> IO ()-appendS16LEFile xs hdl | not (V.null xs) = -  do-    dataList <- (V.mapM takeData . V.fromList) ["-.wav", "0.wav", "1.wav", "A.wav", "B.wav", "C.wav", "D.wav", "E.wav", "F.wav", "G.wav", "H.wav", -        "I.wav", "J.wav", "K.wav", "L.wav", "M.wav", "N.wav", "O.wav", "P.wav", "Q.wav", "R.wav", -          "S.wav", "T.wav", "U.wav", "V.wav", "W.wav", "X.wav", "Y.wav", "Z.wav", "a.wav", "b.wav", "c.wav", -            "d.wav", "e.wav", "f.wav"]-    V.mapM_ (\u -> -      if V.all (\z -> B.length z > 0) dataList -        then let rs =  tail . dropWhile (/= ' ') . takeWhile (/= '}') . show $ hdl in do-          hClose hdl-          closedHdl <- hIsClosed hdl-          if closedHdl -            then B.appendFile rs $ dataList V.! getBFst' (0, V.fromList [("-", 0), ("0", 1), ("1", 2), ("а", 3), ("б", 4), -                     ("в", 5), ("г", 6), ("д", 7), ("дж", 8), ("дз", 9), ("е", 10), ("ж", 11), ("з", 12), ("и", 13), -                        ("й", 14), ("к", 15), ("л", 16), ("м", 17), ("н", 18), ("о", 19), ("п", 20), ("р", 21), -                          ("с", 22), ("сь", 23), ("т", 24), ("у", 25), ("ф", 26), ("х", 27), ("ц", 28), ("ць", 29), ("ч", 30), -                            ("ш", 31), ("ь", 32), ("і", 33), ("ґ", 34)]) u-            else error "File is not closed!"-        else error "Data sound file is not read!") xs-    hClose hdl-                       | otherwise = return ()---- | Function that removes all the sounds with ".raw", ".wav", ".ogg", ".flac" extensions in the current directory. It is used for --- the security reasons.-cleanCreatedSoundFs :: IO ()-cleanCreatedSoundFs = do-  dirCs <- listDirectory "."-  let remFs = concatMap (\ys -> filter (\zs -> ys `isSuffixOf` zs) dirCs) [".raw", ".wav", ".ogg", ".flac"] in mapM_ removeFile remFs
README view
@@ -1,7 +1,8 @@-The executable mmsyn7h is auxilary for the mmsyn7ukr package. +The executable mmsyn7h is auxilary for the mmsyn7ukr package+(https://hackage.haskell.org/package/mmsyn7ukr).  It works similarly to the mmsyn6ukr executable, but uses the voice  sound files in the current directory. This allows to change the  needed files and to produce them by some other means (e. g. by  mmsyn7ukr). Besides, you can remove the created by mmsyn7ukr and mmsyn7h files-during the latter one running.+while the last one is running.
mmsyn7h.cabal view
@@ -2,9 +2,9 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                mmsyn7h-version:             0.2.0.0-synopsis:            A program that is used in mmsyn7ukr and is similar to mmsyn6ukr executable.-description:         A program that is used in mmsyn7ukr and is similar to mmsyn6ukr executable. It uses the data files in the current directory instead of ones in the system defined directories. It reads Ukrainian text with the given by data files sounds.+version:             0.2.1.0+synopsis:            A program and a library that produces a sound recording specified by the Ukrainian text.+description:         A program and a library that are used with mmsyn7ukr (or separately) and are similar to mmsyn6ukr executable. The program uses the data files in the current directory instead of ones in the system defined directories. It reads Ukrainian text with the given by data files sounds. homepage:            https://hackage.haskell.org/package/mmsyn7h license:             MIT license-file:        LICENSE@@ -16,10 +16,19 @@ extra-source-files:  ChangeLog.md, README, Map.txt cabal-version:       >=1.10 +library+  exposed-modules:     MMSyn7h, Main+  -- other-modules:+  -- other-extensions:+  build-depends:       base >=4.7 && <4.14, process >=1.4 && <1.8, vector >=0.11 && <0.14, bytestring >=0.10 && < 0.12, mmsyn2 >=0.1.7 && <1, directory >=1.2.5 && <1.4, mmsyn6ukr >=0.6.2 && <1, mmsyn3 >=0.1.4 && <1+  -- hs-source-dirs:+  default-language:    Haskell2010++ executable mmsyn7h   main-is:             Main.hs   -- other-modules:   -- other-extensions:-  build-depends:       base >=4.7 && <4.14, process >=1.4 && <1.8, vector >=0.11 && <0.14, bytestring >=0.10 && <0.12, mmsyn2 >=0.1.7 && <1, directory >=1.2.5 && <1.4, mmsyn6ukr >=0.6.1 && <1, mmsyn3 >=0.1.4 && <1+  build-depends:       base >=4.7 && <4.14, process >=1.4 && <1.8, vector >=0.11 && <0.14, bytestring >=0.10 && <0.12, mmsyn2 >=0.1.7 && <1, directory >=1.2.5 && <1.4, mmsyn6ukr >=0.6.2 && <1, mmsyn3 >=0.1.4 && <1   -- hs-source-dirs:   default-language:    Haskell2010