watson-developer-cloud/speech-to-text-nodejs

only spanish sorted

Closed this issue · 5 comments

sudo nano /home/felipe/speech-to-text-nodejs/src/data/models.json

###
{
   "models": [
	  {
		 "url": "https://stream.watsonplatform.net/speech-to-text/api/v1/models/es-ES_BroadbandModel", 
		 "rate": 16000, 
		 "name": "es-ES_BroadbandModel", 
		 "language": "es-ES", 
		 "description": "Spanish broadband model."
	  }, 
	  {
		 "url": "https://stream.watsonplatform.net/speech-to-text/api/v1/models/es-ES_NarrowbandModel", 
		 "rate": 8000, 
		 "name": "es-ES_NarrowbandModel", 
		 "language": "es-ES", 
		 "description": "Spanish narrowband model."
	  }
   ]
}

###

sudo nano /home/felipe/speech-to-text-nodejs/src/models.js

##
/**
 * Copyright 2015 IBM Corp. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
'use strict';
var selectModel = require('./views/selectmodel').initSelectModel;

exports.getModels = function(token) {
  var viewContext = {
	currentModel: 'es-ES_BroadbandModel',
	models: null,
	token: token,
	bufferSize: BUFFERSIZE
  };
  var modelUrl = 'https://stream.watsonplatform.net/speech-to-text/api/v1/models';
  var sttRequest = new XMLHttpRequest();
  sttRequest.open('GET', modelUrl, true);
  sttRequest.withCredentials = true;
  sttRequest.setRequestHeader('Accept', 'application/json');
  sttRequest.setRequestHeader('X-Watson-Authorization-Token', token);
  sttRequest.onload = function() {
	var response = JSON.parse(sttRequest.responseText);
	var sorted = response.models.sort(function(a,b) {
	if(a.name > b.name) {
	  return 1;
	}
	if( a.name < b.name) {
	  return -1;
	}
	return 0;
	});
	response.models=sorted;
	 var spansihModels = [];
	   for(var index = 0; index < sorted.length; index++) {
	   var model = sorted[index];
	   if(model.language == 'es-ES') {
		 spansihModels.push(model);
	   }
	}
	response.models=spansihModels;
	localStorage.setItem('models', JSON.stringify(response.models));
	viewContext.models = response.models;
	selectModel(viewContext);
  };
  sttRequest.onerror = function() {
	viewContext.models = require('./data/models.json').models;
	selectModel(viewContext);
  };
  sttRequest.send();
};


##

But is not working

How solved?

I don't understand your goal here. What is the code you are using trying to do and what is wrong with it's output?

I need to show only spanish lang

pantallazo-0072

@johnfelipe

I'm sorry to hear this isn't working for you, and I don't see anything obviously wrong with your code. Perhaps the browserify bundles isn't updated, or your browser is caching older code?

However, this isn't the best place to ask this kind of question. Stack Overflow or DeveloperWorks Answers would be better. Additionally, if possible, you should post a link to your complete code (ideally a github link where people could easily see what was changed from the original code.)

One other thing of note: there is a fairly large update to this demo in the react branch that will be released shortly. You may want to check out that code and see if you can achieve your desired results there, although be warned that it's not quite production-ready, and includes a lot of dead code at the moment.

pantallazo-0103

My short code is not work anymore, pls tell me how show only spanish language 16 and 8 Kkhz

Stay alert

@germanattanasio can u help me with this?