|
2 | 2 | author: eric-urban
|
3 | 3 | ms.service: cognitive-services
|
4 | 4 | ms.topic: include
|
5 |
| -ms.date: 03/11/2020 |
| 5 | +ms.date: 02/28/2023 |
6 | 6 | ms.custom: devx-track-java
|
7 | 7 | ms.author: eur
|
8 | 8 | ---
|
@@ -35,32 +35,13 @@ Choose a platform for installation instructions.
|
35 | 35 |
|
36 | 36 | ## Example
|
37 | 37 |
|
38 |
| -To configure the Speech SDK to accept compressed audio input, create a `PullAudioInputStream` or `PushAudioInputStream`. Then, create an `AudioConfig` from an instance of your stream class that specifies the compression format of the stream. Find related sample code in [Speech SDK samples](https://github.com/Azure-Samples/cognitive-services-speech-sdk/blob/master/samples/java/jre/console/src/com/microsoft/cognitiveservices/speech/samples/console/WavStream.java). |
| 38 | +To configure the Speech SDK to accept compressed audio input, create a `PullAudioInputStream` or `PushAudioInputStream`. Then, create an `AudioConfig` from an instance of your stream class that specifies the compression format of the stream. Find related sample code in [Speech SDK samples](https://github.com/Azure-Samples/cognitive-services-speech-sdk/blob/master/samples/java/android/compressed-input/app/src/main/java/com/microsoft/cognitiveservices/speech/samples/compressedinput/MainActivity.java). |
39 | 39 |
|
40 |
| -Let's assume that you have an input stream class called `pullStream` and are using OPUS/OGG. Your code might look like this: |
| 40 | +Let's assume that you have an input stream class called `pullAudio` and are using MP3. Your code might look like this: |
41 | 41 |
|
42 | 42 | ```java
|
43 |
| -import com.microsoft.cognitiveservices.speech.audio.AudioConfig; |
44 |
| -import com.microsoft.cognitiveservices.speech.audio.AudioInputStream; |
45 |
| -import com.microsoft.cognitiveservices.speech.audio.AudioStreamFormat; |
46 |
| -import com.microsoft.cognitiveservices.speech.audio.PullAudioInputStream; |
47 |
| -import com.microsoft.cognitiveservices.speech.audio.AudioStreamContainerFormat; |
48 |
| - |
49 |
| -// ... omitted for brevity |
50 |
| - |
51 |
| -SpeechConfig speechConfig = |
52 |
| - SpeechConfig.fromSubscription( |
53 |
| - "YourSubscriptionKey", |
54 |
| - "YourServiceRegion"); |
55 |
| - |
56 |
| -// Create an audio config specifying the compressed |
57 |
| -// audio format and the instance of your input stream class. |
58 |
| -PullAudioInputStream pullStream = AudioInputStream.createPullStream( |
59 |
| - AudioStreamFormat.getCompressedFormat(AudioStreamContainerFormat.OGG_OPUS)); |
60 |
| -AudioConfig audioConfig = AudioConfig.fromStreamInput(pullStream); |
61 |
| - |
62 |
| -SpeechRecognizer recognizer = new SpeechRecognizer(speechConfig, audioConfig); |
63 |
| -SpeechRecognitionResult result = recognizer.recognizeOnceAsync().get(); |
64 |
| - |
65 |
| -String text = result.getText(); |
| 43 | +String filePath = "whatstheweatherlike.mp3"; |
| 44 | +PullAudioInputStream pullAudio = AudioInputStream.createPullStream(new BinaryAudioStreamReader(filePath), |
| 45 | + AudioStreamFormat.getCompressedFormat(AudioStreamContainerFormat.MP3)); |
| 46 | +AudioConfig audioConfig = AudioConfig.fromStreamInput(pullAudio); |
66 | 47 | ```
|
0 commit comments