packages feed

speechmatics 0.1.1.0 → 0.2.0.0

raw patch · 4 files changed

+29/−26 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Speechmatics.Client: transcribe :: UserID -> AuthToken -> Options -> [Part] -> IO (Either Error Value)
+ Speechmatics.Client: transcribe :: String -> UserID -> AuthToken -> Options -> [Part] -> IO (Either Error Value)
- Speechmatics.Client: transcribeBytes :: UserID -> AuthToken -> ModelName -> LazyByteFile -> IO (Either Error Value)
+ Speechmatics.Client: transcribeBytes :: String -> UserID -> AuthToken -> ModelName -> LazyByteFile -> IO (Either Error Value)

Files

README.md view
@@ -1,5 +1,9 @@ # speechmatics -a client api for speechmatics.+a client for the [speechmatics](https://app.speechmatics.com/api-details) api .  with input an audio file and blocking untill we get a json transcription.+++Developed by [Daisee](https://www.daisee.com/), pull requests are accepted:+https://bitbucket.org/daisee/speechmatics-api-client
app/Main.hs view
@@ -39,6 +39,6 @@   let mime = (defaultMimeLookup "d.mp3")   print mime   print . sha256 $ bytes-  result <- transcribeBytes userId bearToken "en-US" (LazyByteFile bytes file mime)+  result <- transcribeBytes "https://api.speechmatics.com/v1.0/user/" userId bearToken "en-US" (LazyByteFile bytes file mime)   putStrLn . show $ result 
speechmatics.cabal view
@@ -2,16 +2,17 @@ -- -- see: https://github.com/sol/hpack ----- hash: f064c70f8805662cb580ac9295e710e5488d0a00043850d0d7ff19a5727489cf+-- hash: 1321392778a08e60b2508e7e69fd70c31029767f2a3b62377f7411e4c80d5e9a  name:           speechmatics-version:        0.1.1.0+version:        0.2.0.0 synopsis:       Speechmatics api client description:    Upload audio files to speechmatics to get a transcription category:       API+homepage:       https://bitbucket.org/daisee/speechmatics-api-client/ author:         Jappie Klooster maintainer:     jappie.klooster@daisee.com-copyright:      Daisee+copyright:      Daisee Pty Ltd license:        BSD3 license-file:   LICENSE build-type:     Simple
src/Speechmatics/Client.hs view
@@ -56,9 +56,6 @@  timeout = responseTimeoutMicro 10000 -url :: String-url = "https://api.speechmatics.com/v1.0/user/"- inputName :: Text inputName = pack "data_file" @@ -67,9 +64,9 @@  -- | Transcribe a file that is already loaded in memory --   Does not catch exeptions-transcribeBytes :: UserID -> AuthToken -> ModelName -> LazyByteFile -> IO(Either Error Value)-transcribeBytes userID bearerToken model (LazyByteFile content filename mimetype) = do-  transcribe userID bearerToken defaults parts+transcribeBytes :: String -> UserID -> AuthToken -> ModelName -> LazyByteFile -> IO(Either Error Value)+transcribeBytes url userID bearerToken model (LazyByteFile content filename mimetype) = do+  transcribe url userID bearerToken defaults parts   where     parts = [         partLBS inputName content @@ -87,44 +84,45 @@ tokenUri auth = "?auth_token=" <> auth  slash = mappend . (flip mappend "/") -- play around to much with ghci-jobsUri :: UserID -> String -> String-jobsUri userID x = url <> (show userID) `slash` "jobs" `slash` x+jobsUri :: String -> UserID -> String -> String+jobsUri url userID x = url <> (show userID) `slash` "jobs" `slash` x  -- | More general transcription interface, allows custom parts to be inserted  --   with whatever the user wants. --   Does not catch exeptions-transcribe :: UserID -> AuthToken -> Options -> [Part] -> IO(Either Error Value)-transcribe userID token options parts = do+transcribe :: String -> UserID -> AuthToken -> Options -> [Part] -> IO(Either Error Value)+transcribe uri userID token options parts = do   session <- Sess.newSession   response <- Sess.postWith auth session postUri parts   case Post.parse (response ^. responseBody) of     Left message -> return $ Left $ ParseError message     Right parsed -> do       let jobID = Post.postId parsed-      pollStatus userID token session jobID >>= \case+      pollStatus uri userID token session jobID >>= \case         Just error -> return $ Left $ error         Nothing -> do -          let transcriptUri = jobsUri userID ((show jobID) `slash` "transcript" <> (tokenUri token))+          let transcriptUri = url userID ((show jobID) `slash` "transcript" <> (tokenUri token))           result <- Sess.getWith makeOpts session transcriptUri           return $ first ParseError $ eitherDecode (result ^. responseBody)   where      auth = (withAuthorization options)-    postUri =  jobsUri userID (tokenUri token)+    postUri =  url userID (tokenUri token) +    url = jobsUri uri -pollStatus :: UserID -> AuthToken -> Sess.Session -> JobID -> IO(Maybe Error)-pollStatus userID token session jobID = pollStatus' Nothing userID token session jobID+pollStatus :: String -> UserID -> AuthToken -> Sess.Session -> JobID -> IO(Maybe Error)+pollStatus url userID token session jobID = pollStatus' Nothing url userID token session jobID  waitFor :: Int -> IO() waitFor x = threadDelay (1000000*x) -pollStatus' :: Maybe Integer -> UserID -> AuthToken -> Sess.Session -> JobID -> IO(Maybe Error)-pollStatus' (Just wait) user auth sess jobid = -  waitFor (fromIntegral wait) >> (pollStatus' Nothing) user auth sess jobid-pollStatus' Nothing userID token session jobID = do -  let statusUri = (jobsUri userID $ show $ jobID) <> (tokenUri token)+pollStatus' :: Maybe Integer -> String -> UserID -> AuthToken -> Sess.Session -> JobID -> IO(Maybe Error)+pollStatus' (Just wait) url user auth sess jobid = +  waitFor (fromIntegral wait) >> (pollStatus' Nothing) url user auth sess jobid+pollStatus' Nothing url userID token session jobID = do +  let statusUri = (jobsUri url userID $ show $ jobID) <> (tokenUri token)   statusResponse <- Sess.getWith makeOpts session statusUri   let body = statusResponse ^. responseBody   case second Peek.jobCheckWait (Peek.parse body) of      Left error -> return $ Just $ ParseError error      Right Nothing -> return $ Nothing -- done-    Right maybe -> pollStatus' maybe userID token session jobID+    Right maybe -> pollStatus' maybe url userID token session jobID