diff --git a/samples/batch/csharp/program.cs b/samples/batch/csharp/program.cs index 92d7940eb..0f7889dcc 100644 --- a/samples/batch/csharp/program.cs +++ b/samples/batch/csharp/program.cs @@ -17,10 +17,10 @@ class Program { // // Replace with your subscription key - private const string SubscriptionKey = ""; + private const string SubscriptionKey = "YourSubscriptionKey"; // Update with your service region - private const string HostName = ".cris.ai"; + private const string Region = "YourServiceRegion"; private const int Port = 443; // recordings and locale @@ -52,7 +52,7 @@ static async Task TranscribeAsync() Console.WriteLine("Starting transcriptions client..."); // create the client object and authenticate - var client = BatchClient.CreateApiV2Client(SubscriptionKey, HostName, Port); + var client = BatchClient.CreateApiV2Client(SubscriptionKey, $"{Region}.cris.ai", Port); // get all transcriptions for the subscription var transcriptions = await client.GetTranscriptionsAsync().ConfigureAwait(false); @@ -65,16 +65,18 @@ static async Task TranscribeAsync() await client.DeleteTranscriptionAsync(item.Id).ConfigureAwait(false); } - Console.WriteLine("Creating transcriptions."); var transcriptionLocation = await client.PostTranscriptionAsync(Name, Description, Locale, new Uri(RecordingsBlobUri), modelList).ConfigureAwait(false); + var thisTranscriptionGuid = new Guid(transcriptionLocation.ToString().Split('/').LastOrDefault()); // get the transcription Id from the location URI var createdTranscriptions = new List(); - createdTranscriptions.Add(new Guid(transcriptionLocation.ToString().Split('/').LastOrDefault())); + createdTranscriptions.Add(thisTranscriptionGuid); + + Console.WriteLine($"Created transcription with id {thisTranscriptionGuid}."); Console.WriteLine("Checking status."); - // check for the status of our transcriptions every 30 sec. (can also be 1, 2, 5 min depending on usage) + // check for the status of our transcriptions periodically int completed = 0, running = 0, notStarted = 0; while (completed < 1) { @@ -132,6 +134,7 @@ static async Task TranscribeAsync() // Console.WriteLine(string.Format("Transcriptions status: {0} completed, {1} running, {2} not started yet", completed, running, notStarted)); + // check again after 5 seconds (can also be 1, 2, 5 min depending on usage). await Task.Delay(TimeSpan.FromSeconds(5)).ConfigureAwait(false); } diff --git a/samples/batch/python/README.md b/samples/batch/python/README.md index 000f946b6..5e5377e2f 100644 --- a/samples/batch/python/README.md +++ b/samples/batch/python/README.md @@ -40,8 +40,9 @@ pip install requests The sample code itself is [main.py](python-client/main.py) and can be run using Python 3.5 or higher. You will need to adapt the following information to run the sample: -1. Your subscription key. This must a subscription key for the same region you [downloaded the client](#download-and-install-the-api-client-library) for; it won't work for any other region. +1. Your subscription key and region. 1. The URI of an audio recording in blob storage. 1. (Optional:) The model IDs of both an adapted acoustic and language model, if you want to use a custom model. You can use a development environment like PyCharm to edit, debug, and execute the sample. + diff --git a/samples/batch/python/python-client/main.py b/samples/batch/python/python-client/main.py index 1b5b83277..d12d884f9 100644 --- a/samples/batch/python/python-client/main.py +++ b/samples/batch/python/python-client/main.py @@ -15,9 +15,9 @@ logging.basicConfig(stream=sys.stdout, level=logging.DEBUG, format="%(message)s") -# The subscription key must be for the region that you generated the Swagger -# client library for (see ../README.md for detailed instructions). -SUBSCRIPTION_KEY = "" +# Your subscription key and region for the speech service +SUBSCRIPTION_KEY = "YourSubscriptionKey" +SERVICE_REGION = "YourServiceRegion" NAME = "Simple transcription" DESCRIPTION = "Simple transcription description" @@ -36,6 +36,7 @@ def transcribe(): # configure API key authorization: subscription_key configuration = cris_client.Configuration() configuration.api_key['Ocp-Apim-Subscription-Key'] = SUBSCRIPTION_KEY + configuration.host = "https://{}.cris.ai".format(SERVICE_REGION) # create the client object and authenticate client = cris_client.ApiClient(configuration) @@ -57,8 +58,6 @@ def transcribe(): # ignore swagger error on empty response message body: https://github.com/swagger-api/swagger-core/issues/2446 pass - logging.info("Creating transcriptions.") - # Use base models for transcription. Comment this block if you are using a custom model. # Note: you can specify additional transcription properties by passing a # dictionary in the properties parameter. See @@ -85,6 +84,8 @@ def transcribe(): # get the transcription Id from the location URI created_transcription: str = transcription_location.split('/')[-1] + logging.info("Created new transcription with id {}".format(created_transcription)) + logging.info("Checking status.") completed = False @@ -98,7 +99,7 @@ def transcribe(): # for each transcription in the list we check the status for transcription in transcriptions: if transcription.status in ("Failed", "Succeeded"): - # we check to see if it was one of the transcriptions we created from this client + # we check to see if it was the transcription we created from this client if created_transcription != transcription.id: continue @@ -111,6 +112,8 @@ def transcribe(): logging.info(results.content.decode("utf-8")) else: logging.info("Transcription failed :{}.".format(transcription.status_message)) + + break elif transcription.status == "Running": running += 1 elif transcription.status == "NotStarted":