voicebase-0.1.1.3: app/Main.hs
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Main where
import Data.Aeson (encode)
import qualified Data.ByteString.Lazy as LBS
import qualified Data.ByteString.Lazy.Char8 as C8LBS
import Data.Monoid ((<>))
import qualified Data.Text as Text
import Network.Mime (defaultMimeLookup)
import Options.Applicative
import System.FilePath (splitFileName)
import VoicebaseClient
data Options = Options
{
bearToken :: BearerToken,
file :: FilePath
}
sample :: Parser Options
sample = Options
<$> strOption
( long "bearer-token"
<> metavar "TOKEN"
<> help "The bearer token obtained from voicebase" )
<*> strOption
( long "file"
<> metavar "PATH"
<> help "The file to be posted" )
main :: IO ()
main = execParser opts >>= withBearAndFile
where
opts = info (sample <**> helper)
( fullDesc
<> progDesc "Transcribe a file with voicebase"
<> header "Voicebase transcriber!" )
defaultConfiguration = Configuration {
channels = Just Channels {
left = Speaker "Agent"
, right = Speaker "Caller"
},
language = EnglishAus
}
withBearAndFile :: Options -> IO()
withBearAndFile Options{..} = do
bytes <- LBS.readFile file
result <- transcribeBytes defaultConfiguration bearToken (LazyByteFile bytes filename)
case result of
Left error -> print error
Right r -> C8LBS.putStrLn $ encode $ r
where
filename = defaultMimeLookup . Text.pack . snd . splitFileName $ file