packages feed

mmsyn7ukr 0.4.2.0 → 0.5.0.0

raw patch · 5 files changed

+64/−24 lines, 5 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ SoXBasics: sampleAn :: FilePath -> Integer -> IO (String, String)
- Processing_mmsyn7ukr: beginProcessing :: FilePath -> FilePath -> String -> (String, String) -> IO ()
+ Processing_mmsyn7ukr: beginProcessing :: (FilePath, FilePath) -> String -> (String, String) -> IO ()
- SoXBasics: gainL :: FilePath -> Int -> IO ()
+ SoXBasics: gainL :: FilePath -> Double -> IO ()

Files

ChangeLog.md view
@@ -49,3 +49,7 @@ ## 0.4.2.0 -- 2020-01-02  * Fourth version revised B. Added a new function 'gainL' to the SoXBasics module. Fixed an issue with 'volS' function. Some minor code changes. Some documentation improvements.++## 0.5.0.0 -- 2020-01-05++* Fifth version. Added proper support for Windows for the functions in the SoXBasics and Main modules. Added a new function 'gainL' to the SoXBasics module. Fixed an issue with 'volS' function. Some minor code changes. Some documentation improvements.
Main.hs view
@@ -19,6 +19,7 @@ import Paths_mmsyn6ukr import Processing_mmsyn7ukr import System.Environment (getArgs)+import System.Info (os)  -- | Function responds for general program execution. It starts with CAUTION to be responsible for usage and to  -- use it personally in some important cases (see README). Then the program guides you through the creating your Ukrainian \"voice\". @@ -95,12 +96,17 @@   putStr "response for any possible issues, but by this notification tries to "   putStrLn "intent you to be aware of some possible issues."   putStrLn ""-  onException (do -    let eS = fromJust (showE "sox")-        eSi = fromJust (showE "soxi")-        eSp = fromJust (showE "play")-        eSr = fromJust (showE "rec")-    return ()) (error "SoX is not properly installed in your system. Please, install it properly and then run the program again! ")+  onException (if take 5 os == "mingw" +      then do +        let eS = fromJust (showE "sox")+            eSi = fromJust (showE "soxi")+        return ()+      else do +        let eS = fromJust (showE "sox")+            eSi = fromJust (showE "soxi")+            eSp = fromJust (showE "play")+            eSr = fromJust (showE "rec")+        return ()) (error "SoX is not properly installed in your system. Please, install it properly and then run the program again! ")   paths <- mapM getDataFileName ["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", 
Processing_mmsyn7ukr.hs view
@@ -1,6 +1,6 @@ -- | -- Module      :  Processing_mmsyn7ukr--- Copyright   :  (c) OleksandrZhabenko 2019+-- Copyright   :  (c) OleksandrZhabenko 2019-2020 -- License     :  MIT -- -- Maintainer  :  olexandr543@yahoo.com@@ -52,7 +52,7 @@       do           lim1 <- durationA "_8x.wav"           if lim1 <= 0.0-            then beginProcessing file file1 soundUkr (actsctrl, noiseLim)+            then beginProcessing (file, file1) soundUkr (actsctrl, noiseLim)             else do                resampleA "_8x.wav" (22050::Int)               produceSound4 (file, file1)  "3_8x.wav"@@ -61,7 +61,7 @@           alterVadB "_8x.wav" lim0 noiseMax (duration0*0.04)           lim1 <- durationA "_8x.wav"           if lim1 <= 0.0-            then beginProcessing file file1 soundUkr (actsctrl, noiseLim)+            then beginProcessing (file, file1) soundUkr (actsctrl, noiseLim)             else do                alterVadE "_8x.wav" lim1 noiseMax (duration0*0.04)               resampleA "_8x.wav" (22050::Int)@@ -71,7 +71,7 @@           alterVadB "_8x.wav" lim0 noiseMax (duration0*0.04)           lim1 <- durationA "_8x.wav"           if lim1 <= 0.0-            then beginProcessing file file1 soundUkr (actsctrl, noiseLim)+            then beginProcessing (file, file1) soundUkr (actsctrl, noiseLim)             else do                alterVadE "_8x.wav" lim1 noiseMax (duration0*0.04)               sincA "_8x.wav"@@ -82,7 +82,7 @@           alterVadB "_8x.wav" lim0 noiseMax (duration0*0.04)           lim1 <- durationA "_8x.wav"           if lim1 <= 0.0-            then beginProcessing file file1 soundUkr (actsctrl, noiseLim)+            then beginProcessing (file, file1) soundUkr (actsctrl, noiseLim)             else do                alterVadE "_8x.wav" lim1 noiseMax (duration0*0.1)               sincA "_8x.wav"@@ -154,9 +154,11 @@             | otherwise = xs        -- | Function 'beginProcessing' is used to catch the variant where the sound is fully cut by the SoX because the sound was created in inappropriate time.--- It returns the process to the beginning of the sound recording. For the meaning of the tuple of @Sring@ parameters, refer to 'produceSound' documentation.-beginProcessing :: FilePath -> FilePath -> String -> (String, String) -> IO ()-beginProcessing file file1 soundUkr (actsctrl, noiseLim) = do {+-- It returns the process to the beginning of the sound recording. For the meaning of the tuple of @Sring@ parameters, refer to +-- 'produceSound' documentation. The first @FilePath@ in the tuple of @FilePath@ parameters is a name of the sound file in @mmsyn6ukr@ package. The second one is the +-- name of the resulting file to be produced in the current directory.+beginProcessing :: (FilePath, FilePath) -> String -> (String, String) -> IO ()+beginProcessing (file, file1) soundUkr (actsctrl, noiseLim) = do {   cleanTemp ; putStr "The needed files were NOT created, because the sound was not at the moment of recording! The process will be restarted " ; putStrLn "for the sound. Please, produce a sound during the first 3 seconds (after 0.5 second delay) or specify greater ratio!"
SoXBasics.hs view
@@ -1,6 +1,6 @@ -- | -- Module      :  SoXBasics--- Copyright   :  (c) OleksandrZhabenko 2019+-- Copyright   :  (c) OleksandrZhabenko 2019-2020 -- License     :  MIT -- -- Maintainer  :  olexandr543@yahoo.com@@ -21,6 +21,8 @@ import EndOfExe import System.Exit import Control.Concurrent (threadDelay)+import Control.Exception (onException)+import System.Info (os)  -- | Function 'maxAbs' allows to choose a maximum by absolute value if the values are written as @String@. Bool @True@ corresponds to maximum value, @False@ - to minimum value maxAbs :: (String, String) -> (String, Bool)@@ -145,12 +147,12 @@   then readProcessWithExitCode (fromJust (showE "sox")) [file, "9" ++ file, "gain", "-n", show level] "" >> return ()   else error "SoX is not properly installed in your system. Please, install it properly and then call the function again." --- | Function 'normL' applies a SoX \"gain -b [db-Value]\" effect on the audio file with dB value given by the @Int@ argument. +-- | Function 'normL' applies a SoX \"gain -b [db-Value]\" effect on the audio file with dB value given by the @Double@ argument.  -- The function must be used with the @FilePath@ parameter containing no directories in its name (that mean the file of the @FilePath@ parameter must be  -- in the same directory that also the function is called from).-gainL :: FilePath -> Int -> IO ()+gainL :: FilePath -> Double -> IO () gainL file level = if isJust (showE "sox") -  then readProcessWithExitCode (fromJust (showE "sox")) [file, "9" ++ file, "gain", "-b", show level] "" >> return ()+  then readProcessWithExitCode (fromJust (showE "sox")) [file, "9" ++ file, "gain", "-b", showFFloat (Just 6) level $ show 0] "" >> return ()   else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."  -- | Function 'soxStat' prints a SoX statistics for the audio file.@@ -215,9 +217,13 @@     removeFile $ "3" ++ file   else error "SoX is not properly installed in your system. Please, install it properly and then call the function again." --- | Function 'recA' records audio file with the given name and duration in seconds+-- | Function 'recA' records audio file with the given name and duration in seconds. For Windows it uses a default audio device and \"-t waveaudio -d\" option to the SoX. recA :: FilePath -> Double -> IO ()-recA file x = if isJust (showE "rec") +recA file x | take 5 os == "mingw" =+  if isJust (showE "sox") +  then readProcessWithExitCode (fromJust (showE "sox")) ["-t","waveaudio","-d","-b16", "-c1", "-e", "signed-integer", "-L", file, "trim", "0.5", showFFloat Nothing x $ show 0] "" >> return ()+  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."+            | otherwise = if isJust (showE "rec")    then readProcessWithExitCode (fromJust (showE "rec")) ["-b16", "-c1", "-e", "signed-integer", "-L", file, "trim", "0.5", showFFloat Nothing x $ show 0] "" >> return ()   else error "SoX is not properly installed in your system. Please, install it properly and then call the function again." @@ -238,9 +244,13 @@     let z = read x0::Double in return z   else error "SoX is not properly installed in your system. Please, install it properly and then call the function again." --- | Function 'playA' plays the given file with SoX+-- | Function 'playA' plays the given file with SoX. For Windows it uses \"-t waveaudio -d\" options for SoX. playA :: FilePath -> IO ()-playA file = if isJust (showE "play") +playA file | take 5 os == "mingw" = +  if isJust (showE "sox") +    then readProcessWithExitCode (fromJust (showE "sox")) [file, "-t", "waveaudio", "-d"] "" >> return ()+    else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."+           | otherwise = if isJust (showE "play")    then readProcessWithExitCode (fromJust (showE "play")) [file] "" >> return ()   else error "SoX is not properly installed in your system. Please, install it properly and then call the function again." @@ -309,4 +319,22 @@ sincA :: FilePath -> IO () sincA file = if isJust (showE "sox")    then readProcessWithExitCode (fromJust (showE "sox")) [file, "4." ++ file, "sinc", "-a", "50", "-I", "0.1k-11k"] "" >> return ()+  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."++-- | Function 'sampleAn' analyzes the one samle of the 1-channel sound file (or k samles for the k-channel file) and returns a tuple pair of +-- the maximum and minimum amlitudes of the sound given as @String@s. For the 1-channel sound file they are the same. +-- The @Integer@ parameter is the number of the sample, starting from which SoX analyzes the sound. If it is less than number of the samples available, +-- then the function returns the value for the last one sample for the 1-channel file (or the last k samples for the k-channel sound file). +-- The file must not be in a RAW format for the function to work properly.+sampleAn :: FilePath -> Integer -> IO (String, String)+sampleAn file pos = if isJust (showE "sox") && isJust (showE "soxi")+  then onException (do+    (_, hout, _) <- readProcessWithExitCode (fromJust (showE "soxi")) ["-s", file] ""+    let length0 = read hout::Integer+        f param = do +          (_, _, herr) <- readProcessWithExitCode (fromJust (showE "sox")) [file, "-n", "trim", show param ++ "s", "1s", "stat"] ""+          let lns = map (last . words) . drop 3 . take 5 . lines $ herr in return (head lns, last lns)+    if compare length0 (fromIntegral pos) == GT +      then f pos+      else f (length0 - 1)) (error "SoX cannot determine the number of the samples in the file! May be it is a RAW file and it needs additional parameters to be processed.")   else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."
mmsyn7ukr.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                mmsyn7ukr-version:             0.4.2.0+version:             0.5.0.0 synopsis:            A simple basic interface to some SoX functionality or to produce a voice that can be used by mmsyn7h description:         A program and a library that can be used as a simple basic interface to some SoX functionality or to produce your voice in Ukrainian (if you pronounce the sounds properly) represented by the separate sounds or something special like soft sign. homepage:            https://hackage.haskell.org/package/mmsyn7ukr@@ -10,7 +10,7 @@ license-file:        LICENSE author:              OleksandrZhabenko maintainer:          olexandr543@yahoo.com-copyright:           (c) Oleksandr Zhabenko 2019+copyright:           (c) Oleksandr Zhabenko 2019-2020 category:            Language build-type:          Simple extra-source-files:  ChangeLog.md, README