Shell script for transcription and results
This section shows a simple Linux Bash shell script that demonstrates using the /transcribe
API to upload a file for transcription, and using the /request
to monitor the status of processing that file and retrieve results once transcription has completed.
/request
API, note that the output is written to standard output.#!/bin/bash
#
# Sample script for using the transcribe and request APIs together
#
echo "TEST: Running API tests for transcribe/result mode..."
echo ""
#
if [ $# != 2 ] ; then
echo "Usage: $0 host token"
exit
fi
SERVER=$1
TOKEN=$2
# Uncomment the value of FILE that you want to test with: the
# "standard" version with a file extension, the "guess what kind of
# file" version without a file extension, the standard audio file
# without an extension, or a 7z file. If you're trying something
# without an extension, you'll also have to uncomment the appropriate
# "cp" line.
#
# wvh 03-May-2017
#
# cp ../SAMPLES/CallTEST.mp3 ../SAMPLES/CallTEST
# cp ../SAMPLES/CallTEST.zip ../SAMPLES/CallTEST
# cp ../SAMPLES/CallTEST.7z ../SAMPLES/CallTEST
# SAMPLEFILE=../SAMPLES/CallTEST
# SAMPLEFILE=../SAMPLES/CallTEST.7z
# SAMPLEFILE=../SAMPLES/CallTEST.mp3
# SAMPLEFILE=../SAMPLES/audio-and-metadata.zip
# SAMPLEFILE=../SAMPLES/spanish.zip
# SAMPLEFILE=../SAMPLES/CallTEST.zip
# SAMPLEFILE=../SAMPLES/PERMANENT-FILE.ZIP
# SAMPLEFILE=../SAMPLES/FOO.zip
SAMPLEFILE=../SAMPLES/audio-and-metadata.zip
# SAMPLEFILE=DocTestCo-DocTesting-Test01-Fixed.zip
if [ ! -f $SAMPLEFILE ] ; then
echo " Specified upload ($SAMPLEFILE) does not exist!"
exit
fi
SHORTORG=DocTestCo-DocTesting
FOLDER=Test01
DEBUG="--trace-ascii debug.out"
echo -n "Type of file to upload is: "
file $SAMPLEFILE
echo ""
echo "Submitting $SAMPLEFILE for transcription:"
CMD="curl -s -F token=$TOKEN -F \"file=@$SAMPLEFILE;type=application/zip\" -X POST $SERVER:3000/transcribe/$SHORTORG/$FOLDER $DEBUG"
echo "CMD is $CMD"
echo ""
echo " SUMMARY: Uploading $SAMPLEFILE for transcription at approximately $(date)"
REQUESTID=`curl -s -F token=$TOKEN \
-F "file=@$SAMPLEFILE;type=application/zip" \
-X POST $SERVER:3000/transcribe/$SHORTORG/$FOLDER $DEBUG`
# REQUESTID=`$CMD`
echo ""
if [[ ${REQUESTID} =~ ^[0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{12} ]] ; then
echo " SUMMARY: Upload successful - requestID is \"${REQUESTID}\"..."
else
echo " SUMMARY: RequestID is \"${REQUESTID}\", which is not a valid request ID.."
echo " SUMMARY: Cannot transcribe..."
exit
fi
STATUS=""
# number of second to sleep between retries of status into
SLEEP=10
TOTALWAIT=0
echo "Retrieving status for item submitted via transcribe API..."
echo " Calling curl with \"$SERVER:3000/request/$SHORTORG/status?requestid=$REQUESTID&token=$TOKEN\""
STATUS=`curl -s "$SERVER:3000/request/$SHORTORG/status?requestid=$REQUESTID&token=$TOKEN"`
while [ "x$STATUS" != "xdone" ] ; do
echo " STATUS is \"$STATUS\" - trying again in $SLEEP seconds ($TOTALWAIT so far)..."
sleep $SLEEP
TOTALWAIT=$(($TOTALWAIT + $SLEEP))
STATUS=`curl -s "$SERVER:3000/request/$SHORTORG/status?requestid=$REQUESTID&token=$TOKEN"`
# ((RETRY+=1))
# if [ "x$RETRY" = "x$MAXTRIES" ] ; then
# echo " Quitting due to limit of $MAXTRIES retries..."
# exit 1
# fi
done
echo $REQUESTID > .REQUESTID
echo " SUMMARY: Transcription completed successfully at $(date)"