{-# LANGUAGE OverloadedStrings #-} module Main where import Network.Mime(defaultMimeLookup) import Options import qualified Data.ByteString.Lazy as LBS import Data.Digest.Pure.SHA import System.Log.Heavy import Speechmatics.Client import Network.Mime(MimeType) import Data.Text(pack, Text) import Data.Aeson (decode) import System.Log.Heavy.Backends (defStdoutSettings) import System.Log.Heavy.Types(LoggingSettings(..)) import Data.Maybe data MainOptions = MainOptions { user_id :: Maybe UserID, token :: Maybe String, targetFile :: Maybe FilePath } instance Options MainOptions where defineOptions = pure MainOptions <*> simpleOption "userId" Nothing "The user id obtained from speechmatics" <*> simpleOption "token" Nothing "The bearer token obtained from speechmatics" <*> simpleOption "file" Nothing "The file to be posted" main :: IO () main = runCommand $ \opts args -> do case withBearAndFile <$> user_id opts <*> (Just . pack <$> token opts) <*> targetFile opts of Nothing -> print "wrong options, see --help" Just compute -> compute runStdoutLoggingT = withLoggingT $ LoggingSettings defStdoutSettings withBearAndFile :: UserID -> AuthToken -> FilePath -> IO() withBearAndFile userId bearToken file = do -- result <- transcribeFile bearToken file bytes <- LBS.readFile file let mime = (defaultMimeLookup "d.mp3") print mime print . sha256 $ bytes let json = fromJust $ decode "{ \"type\": \"transcription\", \"transcription_config\": { \"language\": \"en-AU\", \"diarization\": \"channel\", \"channel_diarization_labels\": [\"Agent\", \"Caller\"] } }" result <- runStdoutLoggingT $ transcribeBytes (ByteConfig (Location JsonV2 "https://api.speechmatics.com/v1.0/user/" userId bearToken) -- "{ \"type\": \"transcription\", \"transcription_config\": { \"language\": \"en-AU\", \"diarization\": \"channel\", \"channel_diarization_labels\": [\"Agent\", \"Caller\"] } }") json) (LoadedFile bytes file mime) putStrLn . show $ result