mmsyn6ukr 0.6.6.0 → 0.7.0.0
raw patch · 4 files changed
+88/−45 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Melodics.Executable: circle :: String -> IO ()
+ Melodics.Executable: printInfoF :: IO ()
+ Melodics.Executable: rawToSoundFile :: String -> String -> FilePath -> IO ()
+ Melodics.Executable: workWithInput :: String -> String -> IO ()
Files
- ChangeLog.md +6/−0
- Main.hs +6/−42
- Melodics/Executable.hs +73/−0
- mmsyn6ukr.cabal +3/−3
ChangeLog.md view
@@ -129,3 +129,9 @@ ## 0.6.6.0 -- 2020-05-12 * Sixth version revised G. Changed sound representations for the Ukrainian "б" -- file "B.wav", "к" -- file "M.wav". ++## 0.7.0.0 -- 2020-05-12++* Seventh version. Changed the module structure (and some functions accordinly, too) to more logical and convenient for factorization and composition. +Added a new module Melodics.Executable with the most of the Main module processment functions. Changed the behaviour of the executable +into repeated so you can create many files with it during one runtime operation.
Main.hs view
@@ -10,17 +10,8 @@ module Main where -import Data.Char (isSpace, isControl)-import Data.Maybe (isJust,fromJust)-import System.IO-import System.IO.Unsafe (unsafePerformIO) import System.Environment (getArgs)-import System.Process (callProcess)-import System.Directory (removeFile,findExecutable)-import Control.Exception (bracketOnError)-import EndOfExe (showE)-import Melodics.Ukrainian (appendS16LEFile, convertToProperUkrainian)-import UkrainianLControl+import Melodics.Executable {- -- Inspired by: https://mail.haskell.org/pipermail/beginners/2011-October/008649.html@@ -28,7 +19,8 @@ -- | The function creates a raw PCM sound file with bitrate 22050 Hz 1 mono channel 16-bit signed-integer encoding -- and tries to automatically convert it to the .wav, .ogg, or .flac file with the same parameters specified by the first command line argument--- (for more details see: 'genControl' function) using the system binary SoX. +-- (for more details see: 'genControl' function) using the system binary SoX (this is done for one circle of running, afterwards it is repeated +-- with the same command line arguments. To stop execution, please, interrupt the program e. g. with Ctrl + C on many Unix platforms). -- If it is not installed properly, the program makes ending informational message for the user. -- -- Command line argument is described in more details in the documentation for the 'Melodics.Ukrainian.nSymbols' function. @@ -49,34 +41,6 @@ -- -- The best comression ratio is with the .ogg files, but they lose some quality so be careful if you need it. main :: IO ()-main = bracketOnError (do- args <- getArgs- 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- 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 - xs <- getContents- 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. If there is SoX installed then it will run further. "- let ts = showE "sox" in if isJust ts- then do - if null args - then do - callProcess (fromJust . unsafePerformIO . findExecutable . fromJust $ ts) ["-r22050","-c1","-L","-esigned-integer","-b16", nameSF ++ ".raw", nameSF ++ ".wav"]- removeFile $ nameSF ++ ".raw"- else do- let ws = snd . genControl . head . take 1 $ args in callProcess (fromJust . unsafePerformIO . findExecutable . fromJust $ ts) - ["-r22050","-c1","-L","-esigned-integer","-b16", nameSF ++ ".raw", fst ws, nameSF ++ snd ws]- removeFile $ nameSF ++ ".raw"- else do - putStr "You have a resulting file in a raw PCM format with bitrate 22050 Hz and 1 channel (mono) in the .raw format. "- putStr "You can further process it by yourself manually, otherwise, please, install FFMpeg or LibAV executables in the directory mentioned in the variable PATH"- putStrLn " and then run: "- putStrLn "\"name_of_FFMpeg_or_LibAV_executable\" -f s16le -acodec pcm_s16le -ac 1 -ar 22050 -i \"name_Of_the_sound_file\" \"the_same_name_without_.raw_ending_and_with_.wav_ending\""- putStrLn ""- putStrLn "OR you can install SoX executable in the directory mentioned in the variable PATH and then run: "- putStrLn "\"Path_to_the_SoX_executable\" -b16 -r22050 -c1 -e signed-integer -L \"name_of_the_file_in_raw_format_with_new._prefix\" \"name_of_the_file_in_raw_format_with_new._prefix\" in the terminal.")+main = do+ zs <- fmap (concat . take 1) getArgs+ circle zs
+ Melodics/Executable.hs view
@@ -0,0 +1,73 @@+-- |+-- Module : Melodics.Executable+-- Copyright : (c) OleksandrZhabenko 2019-2020+-- License : MIT+-- Maintainer : olexandr543@yahoo.com+--+-- A program and a library that can be used as a musical instrument synthesizer or for Ukrainian speech synthesis +-- especially for poets, translators and writers. +--++module Melodics.Executable where++import Data.Char (isSpace, isControl)+import Data.Maybe (isJust,fromJust,fromMaybe)+import System.IO+import System.IO.Unsafe (unsafePerformIO)+import System.Process (callProcess)+import System.Directory (removeFile,findExecutable)+import Control.Exception (bracketOnError)+import EndOfExe (showE)+import Melodics.Ukrainian (appendS16LEFile, convertToProperUkrainian)+import UkrainianLControl++-- | Is used to repeat the cycle of creation of the sound files in the current directory for the @mmsyn6ukr@ executable. +circle :: String -> IO ()+circle zs = bracketOnError (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+ return (zs, nameSF)) (\(zs, 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\""+ putStr " 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 "+ putStrLn $ "the command line arguments " ++ show zs ++ " for the file: " ++ show nameSF ++ + ". Please, check also whether the SoX was installed with the support for needed codec.") + (\(zs, nameSF) -> workWithInput zs nameSF >> circle zs)++-- | Interactively creates sound files in the current directory for the Ukrainian text input. Is used internally in the 'circle'+workWithInput :: String -> String -> IO ()+workWithInput zs nameSF + | null nameSF = putStrLn "The program circles now because there is no valid file name provided to be created. "+ | otherwise = do+ xs <- getContents+ let ys = take (nSymbols . fst . genControl $ zs) xs+ withBinaryFile (nameSF ++ ".raw") AppendMode (appendS16LEFile (convertToProperUkrainian ys))+ putStrLn "The .raw file was created by the program. If there is SoX installed then it will run further. "+ let ts = showE "sox" + if isJust ts+ then rawToSoundFile zs nameSF (fromJust ts)+ else printInfoF++-- | Converts RAW sound to the sound file of the needed format in the current directory accordingly to the 'genControl' for the first 'String' argument. +-- Is used internally in the 'workWithInput'.+rawToSoundFile :: String -> String -> FilePath -> IO ()+rawToSoundFile zs nameSF executablePath + | null zs = do + callProcess executablePath ["-r22050","-c1","-L","-esigned-integer","-b16", nameSF ++ ".raw", nameSF ++ ".wav"]+ removeFile $ nameSF ++ ".raw"+ | otherwise = do+ let ws = snd . genControl $ zs+ callProcess executablePath ["-r22050","-c1","-L","-esigned-integer","-b16", nameSF ++ ".raw", fst ws, nameSF ++ snd ws] + removeFile $ nameSF ++ ".raw"++-- | Prints informational message about ending of the possible for the given data program operation on sound files. Is used internally in the 'workWithInput'.+-- Is used internally in the 'workWithInput'.+printInfoF :: IO ()+printInfoF = do + putStr "You have a resulting file in a raw PCM format with bitrate 22050 Hz and 1 channel (mono) in the .raw format. "+ putStr "You can further process it by yourself manually, otherwise, please, install FFMpeg or LibAV executables in the directory mentioned in the variable PATH"+ putStrLn " and then run: "+ putStrLn "\"name_of_FFMpeg_or_LibAV_executable\" -f s16le -acodec pcm_s16le -ac 1 -ar 22050 -i \"name_Of_the_sound_file\" \"the_same_name_without_.raw_ending_and_with_.wav_ending\""+ putStrLn ""+ putStrLn "OR you can install SoX executable in the directory mentioned in the variable PATH and then run: "+ putStrLn "\"Path_to_the_SoX_executable\" -b16 -r22050 -c1 -e signed-integer -L \"name_of_the_file_in_raw_format_with_new._prefix\" \"name_of_the_file_in_raw_format_with_new._prefix\" in the terminal."
mmsyn6ukr.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: mmsyn6ukr-version: 0.6.6.0+version: 0.7.0.0 synopsis: A musical instrument synthesizer or a tool for Ukrainian language listening description: A program can be used as a musical instrument synthesizer or for Ukrainian speech synthesis especially for poets and writers homepage: https://hackage.haskell.org/package/mmsyn6ukr@@ -18,8 +18,8 @@ cabal-version: >=1.10 library- exposed-modules: Paths_mmsyn6ukr, Main, Melodics.Ukrainian, UkrainianLControl- -- other-modules: Melodics.Ukrainian+ exposed-modules: Paths_mmsyn6ukr, Main, Melodics.Ukrainian, Melodics.Executable, UkrainianLControl+ -- other-modules: -- other-extensions: build-depends: base >=4.7 && <4.14, process >=1.4 && <1.8, mmsyn3 >=0.1.4.0 && <1, directory >= 1 && < 1.4, vector >=0.11 && <0.14, bytestring >=0.10 && <0.12, mmsyn2 >=0.1.7 && <1, mmsyn5 >=0.4 && <1 -- hs-source-dirs: