Skip to content

Commit fa8f3f4

Browse files
committed
adding samples
1 parent b4d49d6 commit fa8f3f4

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed

articles/cognitive-services/Speech-Service/speech-container-howto.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,122 @@ For more information on using WSS and HTTPS protocols, see [container security](
411411

412412
[!INCLUDE [Query Speech-to-text container endpoint](includes/speech-to-text-container-query-endpoint.md)]
413413

414+
#### Analyze sentiment
415+
416+
If you provided your Text Analytics API credentials [to the container](#analyze-sentiment-on-the-speech-to-text-output), you can use the Speech SDK to send speech recognition requests with sentiment analysis.
417+
418+
> [!NOTE]
419+
> You can configure API responses to use either a *simple* or *detailed* format.
420+
421+
# [Simple format](#tab/csharp)
422+
423+
To configure the Speech client to use a simple format, add `"Sentiment"` as a value for `Simple.Extensions`. If you want to choose a specific Text Analytics model version, replace `'latest'` in the `speechcontext-phraseDetection.sentimentAnalysis.modelversion` property configuration.
424+
425+
```python
426+
speech_config.set_service_property(
427+
name='speechcontext-PhraseOutput.Simple.Extensions',
428+
value='["Sentiment"]',
429+
channel=speechsdk.ServicePropertyChannel.UriQueryParameter
430+
)
431+
speech_config.set_service_property(
432+
name='speechcontext-phraseDetection.sentimentAnalysis.modelversion',
433+
value='latest',
434+
channel=speechsdk.ServicePropertyChannel.UriQueryParameter
435+
)
436+
```
437+
438+
`Simple.Extensions` will return the sentiment result in root layer of the response.
439+
440+
```json
441+
{
442+
"DisplayText":"What's the weather like?",
443+
"Duration":13000000,
444+
"Id":"6098574b79434bd4849fee7e0a50f22e",
445+
"Offset":4700000,
446+
"RecognitionStatus":"Success",
447+
"Sentiment":{
448+
"Negative":0.03,
449+
"Neutral":0.79,
450+
"Positive":0.18
451+
}
452+
}
453+
```
454+
455+
# [Detailed format](#tab/csharp)
456+
457+
To configure the Speech client to use a detailed format, add `"Sentiment"` as a value for `Detailed.Extensions`, `Detailed.Options`, or both. If you want to choose a specific Text Analytics model version, replace `'latest'` in the `speechcontext-phraseDetection.sentimentAnalysis.modelversion` property configuration.
458+
459+
```python
460+
speech_config.set_service_property(
461+
name='speechcontext-PhraseOutput.Detailed.Options',
462+
value='["Sentiment"]',
463+
channel=speechsdk.ServicePropertyChannel.UriQueryParameter
464+
)
465+
speech_config.set_service_property(
466+
name='speechcontext-PhraseOutput.Detailed.Extensions',
467+
value='["Sentiment"]',
468+
channel=speechsdk.ServicePropertyChannel.UriQueryParameter
469+
)
470+
speech_config.set_service_property(
471+
name='speechcontext-phraseDetection.sentimentAnalysis.modelversion',
472+
value='latest',
473+
channel=speechsdk.ServicePropertyChannel.UriQueryParameter
474+
)
475+
```
476+
477+
`Detailed.Extensions` provides sentiment result in the root layer of the response. `Detailed.Options` provides the result in `NBest` layer of the response. They can be used separately or together.
478+
479+
```json
480+
{
481+
"DisplayText":"What's the weather like?",
482+
"Duration":13000000,
483+
"Id":"6a2aac009b9743d8a47794f3e81f7963",
484+
"NBest":[
485+
{
486+
"Confidence":0.973695,
487+
"Display":"What's the weather like?",
488+
"ITN":"what's the weather like",
489+
"Lexical":"what's the weather like",
490+
"MaskedITN":"What's the weather like",
491+
"Sentiment":{
492+
"Negative":0.03,
493+
"Neutral":0.79,
494+
"Positive":0.18
495+
}
496+
},
497+
{
498+
"Confidence":0.9164971,
499+
"Display":"What is the weather like?",
500+
"ITN":"what is the weather like",
501+
"Lexical":"what is the weather like",
502+
"MaskedITN":"What is the weather like",
503+
"Sentiment":{
504+
"Negative":0.02,
505+
"Neutral":0.88,
506+
"Positive":0.1
507+
}
508+
}
509+
],
510+
"Offset":4700000,
511+
"RecognitionStatus":"Success",
512+
"Sentiment":{
513+
"Negative":0.03,
514+
"Neutral":0.79,
515+
"Positive":0.18
516+
}
517+
}
518+
```
519+
520+
If you want to completely disable sentiment analysis, add a `false` value to `sentimentanalysis.enabled`.
521+
522+
```python
523+
speech_config.set_service_property(
524+
name='speechcontext-phraseDetection.sentimentanalysis.enabled',
525+
value='false',
526+
channel=speechsdk.ServicePropertyChannel.UriQueryParameter
527+
)
528+
```
529+
414530
### Text-to-speech or Custom Text-to-speech
415531

416532
[!INCLUDE [Query Text-to-speech container endpoint](includes/text-to-speech-container-query-endpoint.md)]

0 commit comments

Comments
 (0)