packages feed

mmsyn7ukr 0.9.4.2 → 0.10.0.0

raw patch · 7 files changed

+245/−200 lines, 7 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Processing_mmsyn7ukr: catchEnd :: ThreadId -> IO ()
- Processing_mmsyn7ukr: data SuccessfulEndOfInfo
- Processing_mmsyn7ukr: instance GHC.Exception.Type.Exception Processing_mmsyn7ukr.SuccessfulEndOfInfo
- Processing_mmsyn7ukr: instance GHC.Show.Show Processing_mmsyn7ukr.SuccessfulEndOfInfo
+ FinalException: ExecutableNotProperlyInstalled :: FinalException
+ FinalException: InitialFileNotChanged :: String -> FinalException
+ FinalException: MaybePartiallyTrimmed :: FinalException
+ FinalException: NeededInfoIsShown :: FinalException
+ FinalException: NoiseProfileNotCreatedB :: String -> FinalException
+ FinalException: NoiseProfileNotCreatedE :: String -> FinalException
+ FinalException: NotCreated :: String -> FinalException
+ FinalException: NotCreatedWithEffect :: String -> FinalException
+ FinalException: NotCreatedWithEffects :: String -> FinalException
+ FinalException: NotEnoughData :: String -> FinalException
+ FinalException: NotRecorded :: String -> FinalException
+ FinalException: catchEnd :: FinalException -> IO ()
+ FinalException: data FinalException
+ FinalException: instance GHC.Exception.Type.Exception FinalException.FinalException
+ FinalException: instance GHC.Show.Show FinalException.FinalException

Files

ChangeLog.md view
@@ -160,3 +160,8 @@ ## 0.9.4.2 -- 2020-01-25  * Ninth version revised G. Fixed issue with wrong version number.++## 0.10.0.0 -- 2020-01-28++* Tenth version. Data type changed to FinalException and it is now a separate module FinalException. The error functions in the package is now rewritten+using the new datatype.
+ FinalException.hs view
@@ -0,0 +1,60 @@+-- |+-- Module      :  FinalException+-- Copyright   :  (c) OleksandrZhabenko 2020+-- License     :  MIT+-- Stability   :  Experimental+-- +-- Maintainer  :  olexandr543@yahoo.com+--+-- A program and a library that can be used as a simple +-- basic interface to some SoX functionality or for producing +-- the approximately Ukrainian speech with your own recorded +-- voice (actually it produces the needed sound representations).+--++{-# LANGUAGE DeriveDataTypeable #-}++module FinalException (+  FinalException(..)+  -- * Exception+  , catchEnd+) where++import Data.Typeable+import Control.Exception (Exception, catch, throw)+import System.Environment (getProgName)+import System.IO++-- | Data type 'FinalException' is used to terminate the not needed further execution.+data FinalException = NeededInfoIsShown | ExecutableNotProperlyInstalled | MaybePartiallyTrimmed | NotCreatedWithEffect String+  | InitialFileNotChanged String | NotCreated String | NotRecorded String | NoiseProfileNotCreatedB String | NoiseProfileNotCreatedE String+    | NotEnoughData String | NotCreatedWithEffects String +       deriving ( Typeable )++instance Exception FinalException++instance Show FinalException where+  show NeededInfoIsShown = "NeededInfoIsShown: the program has given you the asked information.\n"+  show (ExecutableNotProperlyInstalled) = "ExecutableNotProperlyInstalled: SoX is not properly installed in your system. Please, install it properly and then call the function again.\n"+  show MaybePartiallyTrimmed = "MaybePartiallyTrimmed: The function did not create the needed file, but may be it trimmed the initial one (not enough)!\n"+  show (NotCreatedWithEffect xs) = "NotCreatedWithEffect: File was not created with " ++ show xs ++ " effect!\n"+  show (InitialFileNotChanged xs) = "InitialFileNotChanged: The initial file " ++ show xs ++ " was not changed!\n"+  show (NotCreated xs) = "NotCreated: The function did not create the needed file " ++ show xs ++ "!\n"+  show (NotRecorded xs) = "NotRecorded: The file " ++ show xs ++ " was not recorded!\n"+  show (NoiseProfileNotCreatedB xs) = "NoiseProfileNotCreatedB: The noise profile " ++ xs ++ ".b.prof was not created!\n"+  show (NoiseProfileNotCreatedE xs) = "NoiseProfileNotCreatedE: The noise profile " ++ xs ++ ".e.prof was not created!\n"+  show (NotEnoughData xs) = "NotEnoughData: SoX cannot determine the number of the samples in the file " ++ show xs +++    "! May be it is a RAW file and it needs additional parameters to be processed.\n"+  show (NotCreatedWithEffects xs) = "NotCreatedWithEffects: File was not created with " ++ (init . unwords . map ((++ ",") . show) . words $ xs) ++ " effects!\n"++-- | Function to work with exception 'FinalException' similarly to the example in the documentation for the 'catch' function. It throws an exception+-- to the thread where it is called. Basically, the function is intended to terminate the program with the informational message (if used in the main thread+-- without exception handler). Because 'NeededInfoIsShown' is exception that actually only is a signal that the needed information is given and is not+-- any exceptional but rather standard situation the output of the function in such a case is printed to the 'stdout' handle (with the default to 'stderr'+-- in all other cases). +catchEnd :: FinalException -> IO ()+catchEnd e = do+  progName <- getProgName+  case e of+    NeededInfoIsShown -> catch (throw e) (\e0 -> hPutStr stdout (progName ++ ": " ++ show (e0 :: FinalException)))+    _                 -> catch (throw e) (\e0 -> hPutStr stderr (progName ++ ": " ++ show (e0 :: FinalException)))
Main.hs view
@@ -15,9 +15,9 @@  module Main where -import Control.Concurrent (myThreadId) import Processing_mmsyn7ukr import System.Environment (getArgs)+import FinalException  -- | Function responds for general @mmsyn7ukr@ program execution.  main :: IO ()@@ -37,10 +37,8 @@        putStrLn "amplitude that are trimmed for the sound file. "        putStr "list-of-produced-sound-representations (if any) -- a list of sound representations, which the program will try to produce while being executed. "        putStrLn "The default one (if not specified) is a full range of needed sound representations. "-       myThread <- myThreadId-       catchEnd myThread+       catchEnd NeededInfoIsShown     "-v" -> do-       putStrLn "mmsyn7ukr version: 0.9.4.2"-       myThread <- myThreadId-       catchEnd myThread+       putStrLn "mmsyn7ukr version: 0.10.0.0"+       catchEnd NeededInfoIsShown     _    -> main7ukr args
Processing_mmsyn7ukr.hs view
@@ -12,12 +12,10 @@ -- voice (actually it produces the needed sound representations). -- -{-# LANGUAGE DeriveDataTypeable #-}  module Processing_mmsyn7ukr (-  SuccessfulEndOfInfo   -- * Main7ukr function-  , main7ukr+  main7ukr   -- * Producing sound   , produceSound   , produceSound2@@ -31,15 +29,13 @@   -- * Cleaning   , cleanTemp   , cleanTempN-  -- * Exception-  , catchEnd ) where -import Control.Concurrent (ThreadId, threadDelay)+import Control.Concurrent (threadDelay) import Data.Typeable import Numeric import System.Directory-import Control.Exception (Exception, IOException, catch, throw, onException)+import Control.Exception (onException) import EndOfExe (showE) import Data.Maybe (fromJust) import Data.Char@@ -52,12 +48,7 @@ import CaseBi (getBFst') import ReplaceP (replaceP, replaceP4) import Paths_mmsyn6ukr---- | Data type 'SuccessfulEndOfInfo' is used to terminate the not needed further execution after being given the needed information.-data SuccessfulEndOfInfo = SuccessfulEndOfInfo-  deriving ( Show, Typeable )--instance Exception SuccessfulEndOfInfo+import FinalException  -- | Function that being given a tuple of @String@ and a path to the installed by the @mmsyn6ukr@ package file produces the corresponding analogous sound with your created  -- voicing. The tuple controls the function behaviour. The first @String@ in it specifies the actions that will be performed to produce a sound file and the second one @@ -301,9 +292,10 @@   filenames <- getDirectoryContents =<< getCurrentDirectory   let rems = filter (\x -> head x == 'n') filenames in mapM_ removeFile rems --- | Function 'tempeRa' is used to create a noise profile for all the recorded sounds. If you provide a 5 seconds silence as needed, the program will+-- | Function 'tempeRa' is used to create a noise profile for all the recorded sounds. The function is used internally in the @mmsyn7ukr@+-- program. While running if you provide a 5 seconds silence as needed, the program @mmsyn7ukr@ will -- reduce the noise in your recordings. This will create a cleaner sound. If you would like not to reduce the noise at all, then, please,--- spcify \"-1\" as the first command line argument for the program @mmsyn7ukr@.+-- specify \"-1\" as the first command line argument for the program @mmsyn7ukr@. tempeRa :: IO () tempeRa = do {     putStrLn "Now, please, be in a silence for 5 seconds so that the program can create a noise profile to remove the noise from the recording. "@@ -458,7 +450,7 @@             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! ")+        return ()) (catchEnd ExecutableNotProperlyInstalled)   tempeRa   let a0 = if null . take 1 $ args               then []@@ -500,12 +492,3 @@   putStrLn "Your voice sound files are now created in the current directory! Use in a secure way! Remember the initial CAUTION! "   putStrLn ""   cleanTempN---- | Function to work with exception 'SuccessfulEndOfInfo' similarly to the example in the documentation for the 'catch' function.-catchEnd :: ThreadId -> IO ()-catchEnd _ = do-  progName <- getProgName-  catch (throw SuccessfulEndOfInfo)-        (\e -> do let end = show (e :: IOException)-                  hPutStr stdout (progName ++ ": " ++ end)-                  return ())
SoXBasics.hs view
@@ -68,6 +68,7 @@ import Control.Concurrent (threadDelay) import Control.Exception (onException) import System.Info (os)+import FinalException  -- | 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)@@ -83,7 +84,9 @@   then do     (_, _, herr) <- readProcessWithExitCode (fromJust (showE "sox")) [file, "-n", "trim", show lowerbound ++ "s", "=" ++ show upperbound ++ "s", "stat"] ""     let zs = lines herr in return (let u = (words $ zs !! 3) !! 2 in if head u == '-' then take 9 u else take 8 u)-  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."+  else do+    catchEnd ExecutableNotProperlyInstalled+    return []  -- | Function 'getMinA' returns a minimum amplitude of the sound in the file in the given lower and upper bounds represented as a tuple of @Int@ values.   getMinA :: FilePath -> (Int, Int) -> IO String@@ -91,7 +94,9 @@   then do     (_, _, herr1) <- readProcessWithExitCode (fromJust (showE "sox")) [file, "-n", "trim", show lowerbound ++ "s", "=" ++ show upperbound ++ "s", "stat"] ""     let zs = lines herr1 in return (let u = (words $ zs !! 4) !! 2 in if head u == '-' then take 9 u else take 8 u)-  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."+  else do+    catchEnd ExecutableNotProperlyInstalled+    return []  -- | Function 'selMaxAbs' returns a maximum by absolute value amplitude of the sound and allows by its second value in the tuple determine whether it is a maximum or minimum.  -- Bool @True@ corresponds to maximum value, @False@ - to minimum value.@@ -130,7 +135,7 @@   then do          lim1 <- durationA file          alterVadHelp file lim1 lim noiseMax exit  -  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."+  else catchEnd ExecutableNotProperlyInstalled    -- | Function 'alterVadHelp' is used internally in the 'alterVadB' and 'alterVadE' functions.  alterVadHelp :: FilePath -> Double -> Double -> Int -> Double -> IO ()@@ -155,8 +160,8 @@                 if e0                   then do                     removeFile $ "7" ++ file-                    error "The function did not create the needed file, but may be it trimmed the initial one (not enough)!"-                  else error "The function did not create the needed file, but may be it trimmed the initial one (not enough)!"+                    catchEnd MaybePartiallyTrimmed+                  else catchEnd MaybePartiallyTrimmed           else alterVadB file (lim1 / 4.0) noiseMax exit                                            | otherwise =   let noiseM = (case noiseMax of @@ -178,8 +183,8 @@                 if e0                   then do                     removeFile $ "7" ++ file-                    error "The function did not create the needed file, but may be it trimmed the initial one (not enough)!"-                  else error "The function did not create the needed file, but may be it trimmed the initial one (not enough)!"+                    catchEnd MaybePartiallyTrimmed+                  else catchEnd MaybePartiallyTrimmed           else alterVadB file (lim / 4.0) noiseMax exit  -- | Function 'opFile' is used internally in 'alterVadB' to check whether @FilePath@ exist and if so to do some processing to allow the 'alterVadB' function iterate further.@@ -207,14 +212,14 @@         if e1           then do             removeFile $ "8" ++ file-            error "File was not created with \"norm\" effect!"-          else error "File was not created with \"norm\" effect!"+            catchEnd (NotCreatedWithEffect "norm")+          else catchEnd (NotCreatedWithEffect "norm")       else do          e2 <- doesFileExist $ "8" ++ file         if e2            then return ()-          else error "The initial file was not changed!"-  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."+          else catchEnd (InitialFileNotChanged file)+  else catchEnd ExecutableNotProperlyInstalled  -- | Function 'normL' applies a SoX gain effect on the audio file with the maximum absolute dB value given by the @Int@ argument.  -- The function must be used with the @FilePath@ parameter containing no directories in its name (that means the file of the @FilePath@ parameter must be @@ -229,14 +234,14 @@         if e1           then do             removeFile $ "9" ++ file-            error "File was not created with \"gain -n\" effect!"-          else error "File was not created with \"gain -n\" effect!"+            catchEnd (NotCreatedWithEffect "gain -n")+          else catchEnd (NotCreatedWithEffect "gain -n")       else do          e2 <- doesFileExist $ "9" ++ file         if e2            then return ()-          else error "The initial file was not changed!"-  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."+          else catchEnd (InitialFileNotChanged file)+  else catchEnd ExecutableNotProperlyInstalled  -- | 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 means the file of the @FilePath@ parameter must be @@ -251,14 +256,14 @@         if e1           then do             removeFile $ "9" ++ file-            error "File was not created with \"gain -b\" effect!"-          else error "File was not created with \"gain -b\" effect!"+            catchEnd (NotCreatedWithEffect "gain -b")+          else catchEnd (NotCreatedWithEffect "gain -b")       else do          e2 <- doesFileExist $ "9" ++ file         if e2            then return ()-          else error "The initial file was not changed!"-  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."+          else catchEnd (InitialFileNotChanged file)+  else catchEnd ExecutableNotProperlyInstalled  -- | Function 'soxStat' prints a SoX statistics for the audio file. soxStat :: FilePath -> IO ()@@ -266,7 +271,7 @@   then do      (_, _, herr) <- readProcessWithExitCode (fromJust (showE "sox")) [file, "-n", "stat"] ""     putStrLn herr-  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."+  else catchEnd ExecutableNotProperlyInstalled    -- | Function 'alterVadE' removes an approximate silence measured by the absolute value of the sound amplitude from the end of the file.  -- The function must be used with the @FilePath@ parameter containing no directories in its name (that means the file of the @FilePath@ parameter must be @@ -284,9 +289,9 @@         if e0           then do             removeFile $ "6" ++ file-            error "The function did not create the needed file!"+            catchEnd (NotCreated file)           else do-            error "The function did not create the needed file!"+            catchEnd (NotCreated file)       else do         alterVadB ("6" ++ file) lim noiseMax exit         (code1, _, _) <- readProcessWithExitCode (fromJust (showE "sox")) ["6" ++ file, "76" ++ file, "reverse"] ""@@ -297,10 +302,10 @@               then do                 removeFile $ "76" ++ file                 removeFile $ "6" ++ file-                error "The function did not create the needed file!"+                catchEnd (NotCreated file)               else do                 removeFile $ "6" ++ file-                error "The function did not create the needed file!"+                catchEnd (NotCreated file)           else do             e2 <- doesFileExist $ "76" ++ file             if e2@@ -310,8 +315,8 @@                 renameFile ("76" ++ file) file               else do                 removeFile $ "6" ++ file-                error "The function did not create the needed file!"-  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."+                catchEnd (NotCreated file)+  else catchEnd ExecutableNotProperlyInstalled  -- | Function 'upperBnd' returns a maximum number of samples for use in other functions. upperBnd :: FilePath -> IO Int@@ -320,7 +325,7 @@     (_, Just hout, _, _) <- createProcess (proc (fromJust (showE "soxi")) ["-s",file]){ std_out = CreatePipe }     x0 <- hGetContents hout     let z = read x0::Int in return z-  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."+  else catchEnd ExecutableNotProperlyInstalled >> return (0::Int)  -- | Variant of the function 'extremeS' with all the additional information included. extremeS1 :: FilePath -> IO Int@@ -343,14 +348,14 @@         if e1           then do             removeFile $ "4" ++ file-            error "File was not created with \"fade\" effect!"-          else error "File was not created with \"fade\" effect!"+            catchEnd (NotCreatedWithEffect "fade q")+          else catchEnd (NotCreatedWithEffect "fade q")       else do          e2 <- doesFileExist $ "4" ++ file         if e2            then return ()-          else error "The initial file was not changed!"-  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."+          else catchEnd (InitialFileNotChanged file)+  else catchEnd ExecutableNotProperlyInstalled  -- | Function 'silenceBoth' adds some silence to both ends of the audio.  -- The function must be used with the @FilePath@ parameter containing no directories in its name (that means the file of the @FilePath@ parameter must be @@ -361,47 +366,41 @@     _ <- readProcessWithExitCode (fromJust (showE "sox")) [file, "3" ++ file, "delay", show beginning ++ "s", "reverse"] ""     _ <- readProcessWithExitCode (fromJust (showE "sox")) ["3" ++ file, "2" ++ file, "delay", show end ++ "s", "reverse"] ""     removeFile $ "3" ++ file-  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."+  else catchEnd ExecutableNotProperlyInstalled  -- | 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 | take 5 os == "mingw" =-  if isJust (showE "sox") -  then do-    (code, _, _) <- readProcessWithExitCode (fromJust (showE "sox")) ["-t","waveaudio","-d","-b16", "-c1", "-esigned-integer", "-L", file, "trim", "0.5", showFFloat Nothing x $ show 0] ""-    if code /= ExitSuccess-      then do-        e0 <- doesFileExist file-        if e0-          then do-            removeFile file-            error $ "The file " ++ file ++ " was not recorded!"-          else do-            error $ "The file " ++ file ++ " was not recorded!"-      else do-        e1 <- doesFileExist file-        if e1-          then return ()-          else error $ "The file " ++ file ++ " was not recorded!"-  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 do-    (code, _, _) <- readProcessWithExitCode (fromJust (showE "rec")) ["-b16", "-c1", "-esigned-integer", "-L", file, "trim", "0.5", showFFloat Nothing x $ show 0] ""-    if code /= ExitSuccess-      then do-        e0 <- doesFileExist file-        if e0-          then do-            removeFile file-            error $ "The file " ++ file ++ " was not recorded!"-          else do-            error $ "The file " ++ file ++ " was not recorded!"-      else do-        e1 <- doesFileExist file-        if e1-          then return ()-          else error $ "The file " ++ file ++ " was not recorded!"-  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."+recA file x | isJust (showE "sox") && take 5 os == "mingw" = do +  (code, _, _) <- readProcessWithExitCode (fromJust (showE "sox")) ["-t","waveaudio","-d","-b16", "-c1", "-esigned-integer", "-L", file, "trim", "0.5", showFFloat Nothing x $ show 0] ""+  if code /= ExitSuccess+    then do+      e0 <- doesFileExist file+      if e0+        then do+          removeFile file+          catchEnd (NotRecorded file)+        else catchEnd (NotRecorded file)+    else do+      e1 <- doesFileExist file+      if e1+        then return ()+        else catchEnd (NotRecorded file)+            | isJust (showE "rec") = do+  (code, _, _) <- readProcessWithExitCode (fromJust (showE "rec")) ["-b16", "-c1", "-esigned-integer", "-L", file, "trim", "0.5", showFFloat Nothing x $ show 0] ""+  if code /= ExitSuccess+    then do+      e0 <- doesFileExist file+      if e0+        then do+          removeFile file+          catchEnd (NotRecorded file)+        else catchEnd (NotRecorded file)+    else do+      e1 <- doesFileExist file+      if e1+        then return ()+        else catchEnd (NotRecorded file)+            | otherwise = catchEnd ExecutableNotProperlyInstalled  -- | Function 'resampleA' changes the sample rate for the recorded audio for further processing.  -- The function must be used with the @FilePath@ parameter containing no directories in its name (that means the file of the @FilePath@ parameter must be @@ -416,14 +415,14 @@         if e1           then do             removeFile $ "3" ++ file-            error "File was not created with \"rate\" effect!"-          else error "File was not created with \"rate\" effect!"+            catchEnd (NotCreatedWithEffect "rate")+          else catchEnd (NotCreatedWithEffect "rate")       else do          e2 <- doesFileExist $ "3" ++ file         if e2            then return ()-          else error "The initial file was not changed!"-  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."+          else catchEnd (InitialFileNotChanged file)+  else catchEnd ExecutableNotProperlyInstalled  -- | Function 'durationA' returns a duration of the audio file in seconds. durationA :: FilePath -> IO Double@@ -432,17 +431,17 @@     (_, Just hout, _, _) <- createProcess (proc (fromJust (showE "soxi")) ["-D",file]){ std_out = CreatePipe }     x0 <- hGetContents hout     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."+  else catchEnd ExecutableNotProperlyInstalled >> return 0.0  -- | Function 'playA' plays the given file with SoX. For Windows it uses \"-t waveaudio -d\" options for SoX. playA :: FilePath -> IO () 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."+    else catchEnd ExecutableNotProperlyInstalled            | 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."+  else catchEnd ExecutableNotProperlyInstalled  -- | Function 'noiseProfB' creates with SoX a file containing a noise profile for the first 0.05 s of the audio file given. noiseProfB :: FilePath -> IO ()@@ -455,14 +454,14 @@         if e0           then do             removeFile $ file ++ ".b.prof"-            error $ "The noise profile " ++ file ++ ".b.prof was not created!"-          else error $ "The noise profile " ++ file ++ ".b.prof was not created!"+            catchEnd (NoiseProfileNotCreatedB file)+          else catchEnd (NoiseProfileNotCreatedB file)       else do          e1 <- doesFileExist $ file ++ ".b.prof"         if e1           then return ()-          else error $ "The noise profile " ++ file ++ ".b.prof was not created!"-  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."+          else catchEnd (NoiseProfileNotCreatedB file)+  else catchEnd ExecutableNotProperlyInstalled  -- | Function 'noiseProfE' creates with SoX a file containing a noise profile for the last 0.05 s of the audio file given.  noiseProfE :: FilePath -> IO ()@@ -475,14 +474,14 @@         if e0           then do             removeFile $ file ++ ".e.prof"-            error $ "The noise profile " ++ file ++ ".e.prof was not created!"-          else error $ "The noise profile " ++ file ++ ".e.prof was not created!"+            catchEnd (NoiseProfileNotCreatedE file)+          else catchEnd (NoiseProfileNotCreatedE file)       else do          e1 <- doesFileExist $ file ++ ".e.prof"         if e1           then return ()-          else error $ "The noise profile " ++ file ++ ".e.prof was not created!"-  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."+          else catchEnd (NoiseProfileNotCreatedE file)+  else catchEnd ExecutableNotProperlyInstalled  -- | Function 'noiseReduceB' reduces with SoX a noise in the file given with the corresponding noise profile created with 'noiseProfB' function.  -- The function must be used with the @FilePath@ parameter containing no directories in its name (that means the file of the @FilePath@ parameter must be @@ -497,14 +496,14 @@         if e1           then do             removeFile $ "_" ++ file-            error "File was not created with \"noisered\" effect!"-          else error "File was not created with \"noisered\" effect!"+            catchEnd (NotCreatedWithEffect "noisered")+          else catchEnd (NotCreatedWithEffect "noisered")       else do          e2 <- doesFileExist $ "_" ++ file         if e2            then return ()-          else error "The initial file was not changed!"-  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."+          else catchEnd (InitialFileNotChanged file)+  else catchEnd ExecutableNotProperlyInstalled  -- | Function 'noiseReduceE' reduces with SoX a noise in the file given with the corresponding noise profile created with 'noiseProfE' function.  -- The function must be used with the @FilePath@ parameter containing no directories in its name (that means the file of the @FilePath@ parameter must be @@ -519,14 +518,14 @@         if e1           then do             removeFile $ "_." ++ file-            error "File was not created with \"noisered\" effect!"-          else error "File was not created with \"noisered\" effect!"+            catchEnd (NotCreatedWithEffect "noisered")+          else catchEnd (NotCreatedWithEffect "noisered")       else do          e2 <- doesFileExist $ "_." ++ file         if e2            then return ()-          else error "The initial file was not changed!"-  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."+          else catchEnd (InitialFileNotChanged file)+  else catchEnd ExecutableNotProperlyInstalled  -- | Function 'volS' changes the given audio with the linear ratio for the amplitude so that the resulting amlitude is equal to the given @Double@ parameter. -- The function must be used with the @FilePath@ parameter containing no directories in its name (that means the file of the @FilePath@ parameter must be @@ -546,19 +545,19 @@               then do                 removeFile $ "8." ++ file                 removeFile $ "8" ++ file-                error "File was not created with \"vol\" effect!"+                catchEnd (NotCreatedWithEffect "vol")               else do                 removeFile $ "8" ++ file-                error "File was not created with \"vol\" effect!"+                catchEnd (NotCreatedWithEffect "vol")           else do              e2 <- doesFileExist $ "8." ++ file             if e2                then return ()               else do                  removeFile $ "8" ++ file-                error "The initial file was not changed!"-      else error "The initial file was not changed!" -  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."+                catchEnd (InitialFileNotChanged file)+      else catchEnd (InitialFileNotChanged file)+  else catchEnd ExecutableNotProperlyInstalled  -- | Function 'volS2' changes the given audio (the first @FilePath@ parameter, which must be normalized e. g. by the 'norm' function before) with  -- the linear ratio for the amplitude so that the resulting amlitude is equal to the maximum by absolute value amplitude for the file given @@ -578,14 +577,14 @@         if e1           then do             removeFile $ "8." ++ tail fileA-            error "File was not created with \"vol\" effect!"-          else error "File was not created with \"vol\" effect!"+            catchEnd (NotCreatedWithEffect "vol")+          else catchEnd (NotCreatedWithEffect "vol")       else do          file8e <- doesFileExist $ "8." ++ tail fileA         if file8e            then return ()-          else error "The initial file was not changed!"-  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."+          else catchEnd (InitialFileNotChanged fileA)+  else catchEnd ExecutableNotProperlyInstalled  -- | Function 'sincA' uses a \"sinc\" effect with @-a 50 -I 0.07k-11k@ band-pass filter for the audio file given. sincA :: FilePath -> IO ()@@ -598,14 +597,14 @@         if e1           then do             removeFile $ "4." ++ file-            error "File was not created with \"sinc\" effect!"-          else error "File was not created with \"sinc\" effect!"+            catchEnd (NotCreatedWithEffect "sinc")+          else catchEnd (NotCreatedWithEffect "sinc")       else do          e0 <- doesFileExist $ "4." ++ file         if e0            then return ()-          else error "The initial file was not changed!"-  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."+          else catchEnd (InitialFileNotChanged file)+  else catchEnd ExecutableNotProperlyInstalled  -- | Function 'sampleAn' analyzes the one samle of the 1-channel sound file (or k samples for the k-channel file) and returns a tuple pair of  -- the maximum and minimum amplitudes of the sound given as @String@s. For the 1-channel sound file they are the same. @@ -622,5 +621,5 @@           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."+      else f (length0 - 1)) (catchEnd (NotEnoughData file))+  else catchEnd ExecutableNotProperlyInstalled >> return ("","")
SoXBasics1.hs view
@@ -44,12 +44,13 @@ import EndOfExe import System.Exit import qualified SoXBasics as SB (extremeS1,upperBnd,selMA,maxAbs,norm)+import FinalException  -- | Function 'norm' applies a SoX normalization effect on the audio file.  -- The function must be used with the @FilePath@ parameter containing no directories in its name (that means the file of the @FilePath@ parameter must be  -- in the same directory where the function is called from). While being -- executed the function tries to replace the initial file with the resulting processed one and to clean the temporary files. If it is not--- successful the function exits with error and leaves the initial file without modification.+-- successful the function exits with exception of the type 'FinalException' and leaves the initial file without modification. norm :: FilePath -> IO () norm file = if isJust (showE "sox")    then do@@ -60,22 +61,22 @@         if e1           then do             removeFile $ "8" ++ file-            error "File was not created with \"norm\" effect!"-          else error "File was not created with \"norm\" effect!"+            catchEnd (NotCreatedWithEffect "norm")+          else catchEnd (NotCreatedWithEffect "norm")       else do          e2 <- doesFileExist $ "8" ++ file         if e2            then do             removeFile file             renameFile ("8" ++ file) file-          else error "The initial file was not changed!"-  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."+          else catchEnd (InitialFileNotChanged file)+  else catchEnd ExecutableNotProperlyInstalled  -- | Function 'normL' applies a SoX gain effect on the audio file with the maximum absolute dB value given by the @Int@ argument.  -- The function must be used with the @FilePath@ parameter containing no directories in its name (that means the file of the @FilePath@ parameter must be  -- in the same directory where the function is called from). While being -- executed the function tries to replace the initial file with the resulting processed one and to clean the temporary files. If it is not--- successful the function exits with error and leaves the initial file without modification.+-- successful the function exits with exception of the type 'FinalException' and leaves the initial file without modification. normL :: FilePath -> Int -> IO () normL file level = if isJust (showE "sox")    then do@@ -86,22 +87,22 @@         if e1           then do             removeFile $ "9" ++ file-            error "File was not created with \"gain -n\" effect!"-          else error "File was not created with \"gain -n\" effect!"+            catchEnd (NotCreatedWithEffect "gain -n")+          else catchEnd (NotCreatedWithEffect "gain -n")       else do          e2 <- doesFileExist $ "9" ++ file         if e2            then do             removeFile file             renameFile ("9" ++ file) file-          else error "The initial file was not changed!"-  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."+          else catchEnd (InitialFileNotChanged file)+  else catchEnd ExecutableNotProperlyInstalled  -- | 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 means the file of the @FilePath@ parameter must be  -- in the same directory where the function is called from). While being -- executed the function tries to replace the initial file with the resulting processed one and to clean the temporary files. If it is not--- successful the function exits with error and leaves the initial file without modification.+-- successful the function exits with exception of the type 'FinalException' and leaves the initial file without modification. gainL :: FilePath -> Double -> IO () gainL file level = if isJust (showE "sox")    then do@@ -112,22 +113,22 @@         if e1           then do             removeFile $ "9" ++ file-            error "File was not created with \"gain\" effect!"-          else error "File was not created with \"gain\" effect!"+            catchEnd (NotCreatedWithEffect "gain -b")+          else catchEnd (NotCreatedWithEffect "gain -b")       else do          e2 <- doesFileExist $ "9" ++ file         if e2            then do             removeFile file             renameFile ("9" ++ file) file-          else error "The initial file was not changed!"-  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."+          else catchEnd (InitialFileNotChanged file)+  else catchEnd ExecutableNotProperlyInstalled  -- | Function 'quarterSinFade' applies a fade effect by SoX to the audio file with \"q\" type.  -- The function must be used with the @FilePath@ parameter containing no directories in its name (that means the file of the @FilePath@ parameter must be  -- in the same directory where the function is called from). While being -- executed the function tries to replace the initial file with the resulting processed one and to clean the temporary files. If it is not--- successful the function exits with error and leaves the initial file without modification.+-- successful the function exits with exception of the type 'FinalException' and leaves the initial file without modification. quarterSinFade :: FilePath -> IO () quarterSinFade file = if isJust (showE "sox")    then do@@ -140,22 +141,22 @@         if e1           then do             removeFile $ "4" ++ file-            error "File was not created with \"fade\" effect!"-          else error "File was not created with \"fade\" effect!"+            catchEnd (NotCreatedWithEffect "fade q")+          else catchEnd (NotCreatedWithEffect "fade q")       else do          e2 <- doesFileExist $ "4" ++ file         if e2            then do             removeFile file             renameFile ("4" ++ file) file-          else error "The initial file was not changed!"-  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."+          else catchEnd (InitialFileNotChanged file)+  else catchEnd ExecutableNotProperlyInstalled  -- | Function 'silenceBoth' adds some silence to both ends of the audio.  -- The function must be used with the @FilePath@ parameter containing no directories in its name (that means the file of the @FilePath@ parameter must be  -- in the same directory where the function is called from). While being -- executed the function tries to replace the initial file with the resulting processed one and to clean the temporary files. If it is not--- successful the function exits with error and leaves the initial file without modification.+-- successful the function exits with exception of the type 'FinalException' and leaves the initial file without modification. silenceBoth :: FilePath -> Int -> Int -> IO () silenceBoth file beginning end = if isJust (showE "sox")    then do@@ -166,8 +167,8 @@         if e1           then do             removeFile $ "3" ++ file-            error "File was not created with \"delay\" and \"reverse\" effects!"-          else error "File was not created with \"delay\" and \"reverse\" effects!"+            catchEnd (NotCreatedWithEffects "delay reverse")+          else catchEnd (NotCreatedWithEffects "delay reverse")       else do          e2 <- doesFileExist $ "3" ++ file         if e2 @@ -180,10 +181,10 @@                   then do                     removeFile $ "3" ++ file                     removeFile $ "2" ++ file-                    error "The resulting file was not created!"+                    catchEnd (NotCreated file)                   else do                     removeFile $ "3" ++ file-                    error "The resulting file was not created!"+                    catchEnd (NotCreated file)               else do                 e3 <- doesFileExist $ "2" ++ file                 if e3@@ -193,15 +194,15 @@                     renameFile ("2" ++ file) file                   else do                     removeFile $ "3" ++ file-                    error "The resulting file was not created!"-          else error "The initial file was not changed!"-  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."+                    catchEnd (NotCreated file)+          else catchEnd (InitialFileNotChanged file)+  else catchEnd ExecutableNotProperlyInstalled  -- | Function 'resampleA' changes the sample rate for the recorded audio for further processing.  -- The function must be used with the @FilePath@ parameter containing no directories in its name (that means the file of the @FilePath@ parameter must be  -- in the same directory where the function is called from). While being -- executed the function tries to replace the initial file with the resulting processed one and to clean the temporary files. If it is not--- successful the function exits with error and leaves the initial file without modification.+-- successful the function exits with exception of the type 'FinalException' and leaves the initial file without modification. resampleA :: FilePath -> Int -> IO () resampleA file frequency = if isJust (showE "sox")    then do@@ -212,22 +213,22 @@         if e1           then do             removeFile $ "3" ++ file-            error "File was not created with \"rate\" effect!"-          else error "File was not created with \"rate\" effect!"+            catchEnd (NotCreatedWithEffect "rate")+          else catchEnd (NotCreatedWithEffect "rate")       else do          e2 <- doesFileExist $ "3" ++ file         if e2            then do             removeFile file             renameFile ("3" ++ file) file-          else error "The initial file was not changed!"-  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."+          else catchEnd (InitialFileNotChanged file)+  else catchEnd ExecutableNotProperlyInstalled  -- | Function 'noiseReduceB' reduces with SoX a noise in the file given with the corresponding noise profile created with 'noiseProfB' function.  -- The function must be used with the @FilePath@ parameter containing no directories in its name (that means the file of the @FilePath@ parameter must be  -- in the same directory where the function is called from). While being -- executed the function tries to replace the initial file with the resulting processed one and to clean the temporary files. If it is not--- successful the function exits with error and leaves the initial file without modification.+-- successful the function exits with exception of the type 'FinalException' and leaves the initial file without modification. noiseReduceB :: FilePath -> IO () noiseReduceB file = if isJust (showE "sox")   then do@@ -238,22 +239,22 @@         if e1           then do             removeFile $ "_" ++ file-            error "File was not created with \"noisered\" effect!"-          else error "File was not created with \"noisered\" effect!"+            catchEnd (NotCreatedWithEffect "noisered")+          else catchEnd (NotCreatedWithEffect "noisered")       else do          e2 <- doesFileExist $ "_" ++ file         if e2            then do             removeFile file             renameFile ("_" ++ file) file-          else error "The initial file was not changed!"-  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."+          else catchEnd (InitialFileNotChanged file)+  else catchEnd ExecutableNotProperlyInstalled  -- | Function 'noiseReduceE' reduces with SoX a noise in the file given with the corresponding noise profile created with 'noiseProfE' function.  -- The function must be used with the @FilePath@ parameter containing no directories in its name (that means the file of the @FilePath@ parameter must be  -- in the same directory where the function is called from). While being -- executed the function tries to replace the initial file with the resulting processed one and to clean the temporary files. If it is not--- successful the function exits with error and leaves the initial file without modification.+-- successful the function exits with exception of the type 'FinalException' and leaves the initial file without modification. noiseReduceE :: FilePath -> IO () noiseReduceE file = if isJust (showE "sox")    then do@@ -264,22 +265,22 @@         if e1           then do             removeFile $ "_." ++ file-            error "File was not created with \"noisered\" effect!"-          else error "File was not created with \"noisered\" effect!"+            catchEnd (NotCreatedWithEffect "noisered")+          else catchEnd (NotCreatedWithEffect "noisered")       else do          e2 <- doesFileExist $ "_." ++ file         if e2            then do             removeFile file             renameFile ("_." ++ file) file-          else error "The initial file was not changed!"-  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."+          else catchEnd (InitialFileNotChanged file)+  else catchEnd ExecutableNotProperlyInstalled  -- | Function 'volS' changes the given audio with the linear ratio for the amplitude so that the resulting amlitude is equal to the given @Double@ parameter. -- The function must be used with the @FilePath@ parameter containing no directories in its name (that means the file of the @FilePath@ parameter must be  -- in the same directory where the function is called from). While being -- executed the function tries to replace the initial file with the resulting processed one and to clean the temporary files. If it is not--- successful the function exits with error and leaves the initial file without modification.+-- successful the function exits with exception of the type 'FinalException' and leaves the initial file without modification. volS :: FilePath -> Double -> IO () volS file amplitude = if isJust (showE "sox")    then do@@ -295,10 +296,10 @@               then do                 removeFile $ "8." ++ file                 removeFile $ "8" ++ file-                error "File was not created with \"vol\" effect!"+                catchEnd (NotCreatedWithEffect "vol")               else do                 removeFile $ "8" ++ file-                error "File was not created with \"vol\" effect!"+                catchEnd (NotCreatedWithEffect "vol")           else do              e2 <- doesFileExist $ "8." ++ file             if e2 @@ -308,16 +309,16 @@                 renameFile ("8." ++ file) file               else do                  removeFile $ "8" ++ file-                error "The initial file was not changed!"-      else error "The initial file was not changed!"-  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."+                catchEnd (InitialFileNotChanged file)+      else catchEnd (InitialFileNotChanged file)+  else catchEnd ExecutableNotProperlyInstalled  -- | Function 'volS2' changes the given audio (the first @FilePath@ parameter, which must be normalized e. g. by the 'norm' function before) with  -- the linear ratio for the amplitude so that the resulting amlitude is equal to the maximum by absolute value amplitude for the file given  -- by the second @FilePath@ parameter. The function must be used with the first @FilePath@ parameter containing no directories in its name  -- (that means the file of the first @FilePath@ parameter must be in the same directory where the function is called from). While being -- executed the function tries to replace the initial file with the resulting processed one and to clean the temporary files. If it is not--- successful the function exits with error and leaves the initial file without modification.+-- successful the function exits with exception of the type 'FinalException' and leaves the initial file without modification. volS2 :: FilePath -> FilePath -> IO () volS2 fileA fileB = if isJust (showE "sox")    then do@@ -332,21 +333,20 @@         if e1           then do             removeFile $ "8." ++ tail fileA-            error "File was not created with \"vol\" effect!"-          else error "File was not created with \"vol\" effect!"+            catchEnd (NotCreatedWithEffect "vol")+          else catchEnd (NotCreatedWithEffect "vol")       else do          file8e <- doesFileExist $ "8." ++ tail fileA         if file8e            then do             removeFile fileA             renameFile ("8." ++ tail fileA) fileA-          else error "The initial file was not changed!"-  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."-        +          else catchEnd (InitialFileNotChanged fileA)+  else catchEnd ExecutableNotProperlyInstalled  -- | Function 'sincA' uses a \"sinc\" effect with @-a 50 -I 0.07k-11k@ band-pass filter for the audio file given. While being -- executed the function tries to replace the initial file with the resulting processed one and to clean the temporary files. If it is not--- successful the function exits with error and leaves the initial file without modification.+-- successful the function exits with exception of the type 'FinalException' and leaves the initial file without modification. sincA :: FilePath -> IO () sincA file = if isJust (showE "sox")    then do@@ -357,13 +357,13 @@         if e1           then do             removeFile $ "4." ++ file-            error "File was not created with \"sinc\" effect!"-          else error "File was not created with \"sinc\" effect!"+            catchEnd (NotCreatedWithEffect "sinc")+          else catchEnd (NotCreatedWithEffect "sinc")       else do          e0 <- doesFileExist $ "4." ++ file         if e0            then do             removeFile file             renameFile ("4." ++ file) file-          else error "The initial file was not changed!"-  else error "SoX is not properly installed in your system. Please, install it properly and then call the function again."+          else catchEnd (InitialFileNotChanged file)+  else catchEnd ExecutableNotProperlyInstalled
mmsyn7ukr.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                mmsyn7ukr-version:             0.9.4.2+version:             0.10.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@@ -17,7 +17,7 @@ cabal-version:       >=1.10  library-  exposed-modules:     SoXBasics, SoXBasics1, Processing_mmsyn7ukr, Main, ReplaceP+  exposed-modules:     SoXBasics, SoXBasics1, Processing_mmsyn7ukr, Main, ReplaceP, FinalException   -- 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