[Voice] Fix google and watson STT pcm format support (#16464)

Signed-off-by: Miguel Álvarez <miguelwork92@gmail.com>
Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
GiviMAD 2024-02-26 23:03:39 -08:00 committed by Ciprian Pascu
parent d4cdd56097
commit cb8b3fb125
2 changed files with 5 additions and 6 deletions

View File

@ -243,7 +243,7 @@ public class GoogleSTTService implements STTService {
// Gather stream info and send config // Gather stream info and send config
AudioFormat streamFormat = audioStream.getFormat(); AudioFormat streamFormat = audioStream.getFormat();
RecognitionConfig.AudioEncoding streamEncoding; RecognitionConfig.AudioEncoding streamEncoding;
if (AudioFormat.WAV.isCompatible(streamFormat)) { if (AudioFormat.PCM_SIGNED.isCompatible(streamFormat) || AudioFormat.WAV.isCompatible(streamFormat)) {
streamEncoding = RecognitionConfig.AudioEncoding.LINEAR16; streamEncoding = RecognitionConfig.AudioEncoding.LINEAR16;
} else { } else {
logger.debug("Unsupported format {}", streamFormat); logger.debug("Unsupported format {}", streamFormat);

View File

@ -208,6 +208,10 @@ public class WatsonSTTService implements STTService {
Long frequency = format.getFrequency(); Long frequency = format.getFrequency();
Integer bitDepth = format.getBitDepth(); Integer bitDepth = format.getBitDepth();
switch (container) { switch (container) {
case AudioFormat.CONTAINER_NONE:
if (AudioFormat.CODEC_MP3.equals(codec)) {
return "audio/mp3";
}
case AudioFormat.CONTAINER_WAVE: case AudioFormat.CONTAINER_WAVE:
if (AudioFormat.CODEC_PCM_SIGNED.equals(codec)) { if (AudioFormat.CODEC_PCM_SIGNED.equals(codec)) {
if (bitDepth == null || bitDepth != 16) { if (bitDepth == null || bitDepth != 16) {
@ -239,11 +243,6 @@ public class WatsonSTTService implements STTService {
return "audio/ogg;codecs=opus"; return "audio/ogg;codecs=opus";
} }
break; break;
case AudioFormat.CONTAINER_NONE:
if (AudioFormat.CODEC_MP3.equals(codec)) {
return "audio/mp3";
}
break;
} }
return null; return null;
} }