Skip to content

Commit 2eab7e0

Browse files
authored
Merge pull request #452 from chughts/ogg
OGG mime type of audio/opus correction
2 parents a6668e6 + 6ada624 commit 2eab7e0

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ Node-RED Watson Nodes for IBM Cloud
77

88
<a href="https://cla-assistant.io/watson-developer-cloud/node-red-node-watson"><img src="https://cla-assistant.io/readme/badge/watson-developer-cloud/node-red-node-watson" alt="CLA assistant" /></a>
99

10+
### New in version 0.7.7
11+
- STT Node - Set correct content-type when File-Type reports a mime type of audio/opus for ogg;codec=opus files.
12+
1013
### New in version 0.7.6
1114
- Bump SDK Dependency to 3.18.2
1215
- STT Node To use iam-utils in place of removed iam-token-manager

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "node-red-node-watson",
3-
"version": "0.7.6",
3+
"version": "0.7.7",
44
"description": "A collection of Node-RED nodes for IBM Watson services",
55
"dependencies": {
66
"async": "^1.5.2",
77
"cfenv": "~1.0.0",
8-
"file-type": "^10.7.0",
8+
"file-type": "^10.9.0",
99
"request": "~2.86.0",
1010
"temp": "^0.9.0",
1111
"qs": "6.x",

services/speech_to_text/v1.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ module.exports = function (RED) {
176176
case 'mpeg':
177177
break;
178178
default:
179-
message = 'Audio format (' + f + ') not supported, must be encoded as WAV, MP3, FLAC or OGG.';
179+
if (! ft.mime.toLowerCase().includes('audio')) {
180+
message = 'Audio format (' + f + ') not supported, must be encoded as WAV, MP3, FLAC or OGG.';
181+
}
180182
}
181183
}
182184
if (message) {
@@ -192,6 +194,24 @@ module.exports = function (RED) {
192194
return payloadNonStreamCheck(msg);
193195
}
194196

197+
function setFormat(format) {
198+
// if the format is being seen as either opus or vorbis, then it
199+
// could be one of
200+
// audio/ogg;codecs=opus
201+
// audio/ogg;codecs=vorbis
202+
// audio/webm;codecs=opus
203+
// audio/webm;codecs=vorbis
204+
// there isn't enough information to decide between audio/ogg and audio/webm
205+
// so lets go with audio/ogg
206+
switch (format) {
207+
case 'opus':
208+
case 'vorbis':
209+
return 'ogg;codecs=' + format;
210+
default:
211+
return format;
212+
}
213+
}
214+
195215
function processInputBuffer(msg) {
196216
var p = new Promise(function resolver(resolve, reject){
197217
temp.open({suffix: '.' + fileType(msg.payload).ext}, (err, info) => {
@@ -203,7 +223,8 @@ module.exports = function (RED) {
203223
audio = fs.createReadStream(info.path);
204224

205225
audioData.audio = audio;
206-
audioData.format = format;
226+
audioData.format = setFormat(format);
227+
207228
resolve(audioData);
208229
});
209230
});
@@ -225,7 +246,7 @@ module.exports = function (RED) {
225246
audio = fs.createReadStream(info.path);
226247

227248
audioData.audio = audio;
228-
audioData.format = format;
249+
audioData.format = setFormat(format);
229250
resolve(audioData);
230251
});
231252
});

0 commit comments

Comments
 (0)