Skip to content

Commit

Permalink
Read speech and AOAI configurations via env variables (#2654)
Browse files Browse the repository at this point in the history
* Support speech, aoai configurations via env variables

* README.md changes to reflect argument changes

---------

Co-authored-by: Yulin Li <[email protected]>
Co-authored-by: Ryan Hurey <[email protected]>
  • Loading branch information
3 people authored Nov 14, 2024
1 parent 6cd3506 commit d1d254e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 29 deletions.
17 changes: 10 additions & 7 deletions scenarios/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,20 @@ This sample application transcribes an audio recording using <a href="https://le

### Usage

* `--speechKey KEY`: Your <a href="https://portal.azure.com/#create/Microsoft.CognitiveServicesAllInOne" title="Create a Cognitive Services resource" target="_blank">Cognitive Services</a> or <a href="https://portal.azure.com/#create/Microsoft.CognitiveServicesSpeechServices" title="Create a Speech resource" target="_blank">Speech</a> resource key. Required.
* `--speechRegion REGION`: Your <a href="https://portal.azure.com/#create/Microsoft.CognitiveServicesAllInOne" title="Create a Cognitive Services resource" target="_blank">Cognitive Services</a> or <a href="https://portal.azure.com/#create/Microsoft.CognitiveServicesSpeechServices" title="Create a Speech resource" target="_blank">Speech</a> resource region. Examples: `eastus`, `northeurope` Required.
`Usage : post-call-analytics <inputAudio> [options]`

* `--openAiKey KEY`: Your <a href="https://ms.portal.azure.com/#create/Microsoft.CognitiveServicesOpenAI" title="Create an Azure OpenAI resource" target="_blank">Azure OpenAI</a> resource key. Required.
* `--openAiEndpoint ENDPOINT`: Your <a href="https://portal.azure.com/#create/Microsoft.CognitiveServicesAllInOne" title="Create an Azure OpenAI resource" target="_blank">Azure OpenAI</a> resource endpoint. Example: `https://YourResourceName.openai.azure.com` Required.
* `--openAiDeploymentName OPENAIDEPLOYMENTNAME`: Your <a href="https://portal.azure.com/#create/Microsoft.CognitiveServicesAllInOne" title="Create an Azure OpenAI resource" target="_blank">Azure OpenAI</a> deployment name. Example: my-gpt-4o-mini Required.

* `--inputAudio FILEPATH`: File path to audio. Required.
Arguments:
* ``<inputAudio>``: Path to the audio file. Required.

Options:
* `--speechKey KEY`: Your <a href="https://portal.azure.com/#create/Microsoft.CognitiveServicesAllInOne" title="Create a Cognitive Services resource" target="_blank">Cognitive Services</a> or <a href="https://portal.azure.com/#create/Microsoft.CognitiveServicesSpeechServices" title="Create a Speech resource" target="_blank">Speech</a> resource key. The value can also be set via SPEECH_KEY environment variable. Required.
* `--speechRegion REGION`: Your <a href="https://portal.azure.com/#create/Microsoft.CognitiveServicesAllInOne" title="Create a Cognitive Services resource" target="_blank">Cognitive Services</a> or <a href="https://portal.azure.com/#create/Microsoft.CognitiveServicesSpeechServices" title="Create a Speech resource" target="_blank">Speech</a> resource region. The value can also be set via SPEECH_REGION environment variable. Examples: `eastus`, `northeurope`. Required.
* `--openAiKey KEY`: Your <a href="https://ms.portal.azure.com/#create/Microsoft.CognitiveServicesOpenAI" title="Create an Azure OpenAI resource" target="_blank">Azure OpenAI</a> resource key. The value can also be set via AOAI_KEY environment variable. Optional.
* `--openAiEndpoint ENDPOINT`: Your <a href="https://portal.azure.com/#create/Microsoft.CognitiveServicesAllInOne" title="Create an Azure OpenAI resource" target="_blank">Azure OpenAI</a> resource endpoint. Example: `https://YourResourceName.openai.azure.com`. The value can also be set via AOAI_ENDPOINT environment variable. Optional.
* `--openAiDeploymentName OPENAIDEPLOYMENTNAME`: Your <a href="https://portal.azure.com/#create/Microsoft.CognitiveServicesAllInOne" title="Create an Azure OpenAI resource" target="_blank">Azure OpenAI</a> deployment name. The value can also be set via AOAI_DEPLOYMENT_NAME environment variable. Example: my-gpt-4o-mini. Optional.
* `--help`: Show the usage help and stop


## Call Center Transcription and Analytics

Visit the [call center transcription quickstart](https://learn.microsoft.com/azure/cognitive-services/speech-service/call-center-quickstart) for a detailed guide on how to get started transcribing call recordings using the Speech and Language Services.
Expand Down
47 changes: 33 additions & 14 deletions scenarios/csharp/dotnetcore/post-call-analytics/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,46 @@ internal static async Task<string> SummarizeAsync(string openAiKey, string openA

internal static async Task AnalyzeAudioAsync(string speechKey, string speechRegion, FileInfo inputAudio, string openAiKey, string openAiEndpoint, string deploymentOrModelName)
{
if (string.IsNullOrEmpty(speechKey) || string.IsNullOrEmpty(speechRegion) || (inputAudio == null || !inputAudio.Exists) || string.IsNullOrEmpty(openAiKey) || string.IsNullOrEmpty(openAiEndpoint) || string.IsNullOrEmpty(deploymentOrModelName))
{
Console.WriteLine("Error: missing required option");
return;
}

var transcription = await TranscribeAsync(speechKey, speechRegion, inputAudio);
Console.WriteLine($"Transcription: {transcription}");

var summary = await SummarizeAsync(openAiKey, openAiEndpoint, deploymentOrModelName, transcription);
Console.WriteLine($"Summary: {summary}");
if (!string.IsNullOrEmpty(openAiKey) && !string.IsNullOrEmpty(openAiEndpoint) && !string.IsNullOrEmpty(deploymentOrModelName))
{
var summary = await SummarizeAsync(openAiKey, openAiEndpoint, deploymentOrModelName, transcription);
Console.WriteLine($"Summary: {summary}");
}
else
{
Console.WriteLine($"Missing AOAI configuration. Skipping Summarization");
}
}

public async static Task<int> Main(string[] args)
{
var inputAudio = new Option<FileInfo>(name: "--inputAudio", description: "Path to the audio file. Required.");
var speechKey = new Option<string>(name: "--speechKey", description: "Your Cognitive Services or Speech resource key. Required.");
var speechRegion = new Option<string>(name: "--speechRegion", description: "Your Cognitive Services or Speech resource region. Example: eastus, northeurope. Required.");
var openAiKey = new Option<string>(name: "--openAiKey", description: "Your Azure OpenAI resource key. Required.");
var openAiEndpoint = new Option<string>(name: "--openAiEndpoint", description: "Your Azure OpenAI resource endpoint. Required. Example: https://YourResourceName.openai.azure.com");
var openAiDeploymentName = new Option<string>(name: "--openAiDeploymentName", description: "Your Azure OpenAI deployment name. Example: my-gpt-4o-mini. Required.");
var inputAudio = new Argument<FileInfo>(name: "inputAudio", description: "Path to the audio file. Required.");

// Speech service is used for transcription.
var speechKey = new Option<string>(name: "--speechKey", description: "Your Cognitive Services or Speech resource key. Required.", getDefaultValue: () => Environment.GetEnvironmentVariable("SPEECH_KEY"));
speechKey.AddValidator(result =>
{
if (string.IsNullOrEmpty(result.GetValueForOption(speechKey)))
{
result.ErrorMessage = $"Speech key is required. Set via --{speechKey.Name} or SPEECH_KEY environment variable.";
}
});
var speechRegion = new Option<string>(name: "--speechRegion", description: "Your Cognitive Services or Speech resource region. Example: eastus, northeurope. Required.", getDefaultValue: () => Environment.GetEnvironmentVariable("SPEECH_REGION"));
speechRegion.AddValidator(result =>
{
if (string.IsNullOrEmpty(result.GetValueForOption(speechRegion)))
{
result.ErrorMessage = $"Speech region is required. Set via --{speechRegion.Name} or SPEECH_REGION environment variable.";
}
});

// AOAI is used for summarization. This step is optional.
var openAiKey = new Option<string>(name: "--openAiKey", description: "Your Azure OpenAI resource key. Optional.", getDefaultValue: () => Environment.GetEnvironmentVariable("AOAI_KEY"));
var openAiEndpoint = new Option<string>(name: "--openAiEndpoint", description: "Your Azure OpenAI resource endpoint. Optional. Example: https://YourResourceName.openai.azure.com", getDefaultValue: () => Environment.GetEnvironmentVariable("AOAI_ENDPOINT"));
var openAiDeploymentName = new Option<string>(name: "--openAiDeploymentName", description: "Your Azure OpenAI deployment name. Example: my-gpt-4o-mini. Optional.", getDefaultValue: () => Environment.GetEnvironmentVariable("AOAI_DEPLOYMENT_NAME"));

var rootCommand = new RootCommand()
{
Expand Down
18 changes: 10 additions & 8 deletions scenarios/csharp/dotnetcore/post-call-analytics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ This sample application transcribes an audio recording using <a href="https://le
## Prerequisites
- .NET 6.0 SDK or higher

## Command-line Options
## Usage

* `--speechKey KEY`: Your <a href="https://portal.azure.com/#create/Microsoft.CognitiveServicesAllInOne" title="Create a Cognitive Services resource" target="_blank">Cognitive Services</a> or <a href="https://portal.azure.com/#create/Microsoft.CognitiveServicesSpeechServices" title="Create a Speech resource" target="_blank">Speech</a> resource key. Required.
* `--speechRegion REGION`: Your <a href="https://portal.azure.com/#create/Microsoft.CognitiveServicesAllInOne" title="Create a Cognitive Services resource" target="_blank">Cognitive Services</a> or <a href="https://portal.azure.com/#create/Microsoft.CognitiveServicesSpeechServices" title="Create a Speech resource" target="_blank">Speech</a> resource region. Examples: `eastus`, `northeurope` Required.
`Usage : post-call-analytics <inputAudio> [options]`

* `--openAiKey KEY`: Your <a href="https://ms.portal.azure.com/#create/Microsoft.CognitiveServicesOpenAI" title="Create an Azure OpenAI resource" target="_blank">Azure OpenAI</a> resource key. Required.
* `--openAiEndpoint ENDPOINT`: Your <a href="https://portal.azure.com/#create/Microsoft.CognitiveServicesAllInOne" title="Create an Azure OpenAI resource" target="_blank">Azure OpenAI</a> resource endpoint. Example: `https://YourResourceName.openai.azure.com` Required.
* `--openAiDeploymentName OPENAIDEPLOYMENTNAME`: Your <a href="https://portal.azure.com/#create/Microsoft.CognitiveServicesAllInOne" title="Create an Azure OpenAI resource" target="_blank">Azure OpenAI</a> deployment name. Example: my-gpt-4o-mini Required.

* `--inputAudio FILEPATH`: File path to audio. Required.
Arguments:
* ``<inputAudio>``: Path to the audio file. Required.

Options:
* `--speechKey KEY`: Your <a href="https://portal.azure.com/#create/Microsoft.CognitiveServicesAllInOne" title="Create a Cognitive Services resource" target="_blank">Cognitive Services</a> or <a href="https://portal.azure.com/#create/Microsoft.CognitiveServicesSpeechServices" title="Create a Speech resource" target="_blank">Speech</a> resource key. The value can also be set via SPEECH_KEY environment variable. Required.
* `--speechRegion REGION`: Your <a href="https://portal.azure.com/#create/Microsoft.CognitiveServicesAllInOne" title="Create a Cognitive Services resource" target="_blank">Cognitive Services</a> or <a href="https://portal.azure.com/#create/Microsoft.CognitiveServicesSpeechServices" title="Create a Speech resource" target="_blank">Speech</a> resource region. The value can also be set via SPEECH_REGION environment variable. Examples: `eastus`, `northeurope`. Required.
* `--openAiKey KEY`: Your <a href="https://ms.portal.azure.com/#create/Microsoft.CognitiveServicesOpenAI" title="Create an Azure OpenAI resource" target="_blank">Azure OpenAI</a> resource key. The value can also be set via AOAI_KEY environment variable. Optional.
* `--openAiEndpoint ENDPOINT`: Your <a href="https://portal.azure.com/#create/Microsoft.CognitiveServicesAllInOne" title="Create an Azure OpenAI resource" target="_blank">Azure OpenAI</a> resource endpoint. Example: `https://YourResourceName.openai.azure.com`. The value can also be set via AOAI_ENDPOINT environment variable. Optional.
* `--openAiDeploymentName OPENAIDEPLOYMENTNAME`: Your <a href="https://portal.azure.com/#create/Microsoft.CognitiveServicesAllInOne" title="Create an Azure OpenAI resource" target="_blank">Azure OpenAI</a> deployment name. The value can also be set via AOAI_DEPLOYMENT_NAME environment variable. Example: my-gpt-4o-mini. Optional.
* `--help`: Show the usage help and stop

0 comments on commit d1d254e

Please sign in to comment.