52
52
* <b>frame-width</b> (integer): speech frame width, in ms
53
53
* </li>
54
54
* <li>
55
- * <b>locale</b> (string): language code for speech recognition
55
+ * <b>locale</b> (string): BCP-47 language code for speech recognition
56
56
* </li>
57
57
* <li>
58
58
* <b>azure-api-key</b> (string): API key for the Azure Speech
@@ -70,6 +70,7 @@ public class AzureSpeechRecognizer implements SpeechProcessor {
70
70
private PushAudioInputStream audioStream ;
71
71
private AudioConfig audioConfig ;
72
72
private boolean active ;
73
+ private String locale ;
73
74
74
75
// Azure speech requires little-endian (wav-format) data, so we buffer
75
76
// audio frames internally to avoid mutating data coming from the speech
@@ -86,6 +87,10 @@ public AzureSpeechRecognizer(SpeechConfig speechConfig) {
86
87
String region = speechConfig .getString ("azure-region" );
87
88
int sampleRate = speechConfig .getInteger ("sample-rate" );
88
89
90
+ if (speechConfig .containsKey ("locale" )) {
91
+ this .locale = speechConfig .getString ("locale" );
92
+ }
93
+
89
94
if (sampleRate != 16000 ) {
90
95
throw new IllegalArgumentException (
91
96
"Azure only supports a 16kHz sample rate; found: "
@@ -103,6 +108,11 @@ com.microsoft.cognitiveservices.speech.SpeechConfig createMsConfig(
103
108
com .microsoft .cognitiveservices .speech .SpeechConfig
104
109
.fromSubscription (apiKey , region );
105
110
config .setProfanity (ProfanityOption .Raw );
111
+
112
+ if (this .locale != null ) {
113
+ config .setSpeechRecognitionLanguage (this .locale );
114
+ }
115
+
106
116
return config ;
107
117
}
108
118
0 commit comments