/*jshint node:true*/

// app.js
// This file contains the server side JavaScript code for your application.
// This sample application uses express as web application framework (http://expressjs.com/),

var express = require('express');

// setup middleware
var app = express();
app.use(app.router);
app.use(express.errorHandler());
app.use(express.static(__dirname + '/public')); //setup static public directory

// There are many useful environment variables available in process.env.
// VCAP_APPLICATION contains useful information about a deployed application.
var appInfo = JSON.parse(process.env.VCAP_APPLICATION || "{}");
// TODO: Get application information and use it in your app.

// VCAP_SERVICES contains all the credentials of services bound to
// this application. For details of its content, please refer to
// the document or sample of each service.
var services = JSON.parse(process.env.VCAP_SERVICES || "{}");
// TODO: Get service credentials and communicate with bluemix services.

// The IP address of the Cloud Foundry DEA (Droplet Execution Agent) that hosts this application:
var host = (process.env.VCAP_APP_HOST || 'localhost');
// The port on the DEA for communication with the application:
var port = (process.env.VCAP_APP_PORT || 3000);
// Start server
app.listen(port, host);
console.log('App started on port ' + port);


@@ -18,220 +18,101 @@
 e*/%0A
-%0A
 //
- app.js%0A// This file contains the server side JavaScript code for your application.%0A// This sample application uses express as web application framework (http://expressjs.com/),%0A%0Avar express = require('express
+Dependencies%0Avar express = require('express');%0Avar watson = require('watson-developer-cloud
 ');%0A
@@ -121,16 +121,23 @@
 / setup 
+server 
 middlewa
@@ -298,594 +298,1769 @@
 ory%0A
-%0A// There are many useful environment variables available in process.env.%0A// VCAP_APPLICATION contains useful information about a deployed application.%0Avar appInfo = JSON.parse(process.env.VCAP_APPLICATION %7C%7C %22%7B%7D%22);%0A// TODO: Get application information and use it in your app.%0A%0A// VCAP_SERVICES contains all the credentials of services bound to%0A// this application. For details of its content, please refer to%0A// the document or s
+app.use(express.static(__dirname + '/bower_components'));%0A// Bluemix app & service info%0Avar appInfo = JSON.parse(process.env.VCAP_APPLICATION %7C%7C %22%7B%7D%22);%0A// TODO: Get application information and use it in your app.%0Avar services = JSON.parse(process.env.VCAP_SERVICES %7C%7C %22%7B%7D%22);%0A// TODO: Get service credentials and communicate with bluemix services.%0A%0Avar speech_to_text = watson.speech_to_text(%7B%0A  username: '3356150d-abe8-4612-95e2-16afa492a24f',%0A  password: 'gVNaGjswkXeV',%0A  version: 'v1'%0A%7D);%0A%0Avar text_to_speech = watson.text_to_speech(%7B%0A  username: '8e3ad5ac-49f2-4524-8aec-52ee475eedb6',%0A  password: 'v3DXJzQRfSEX', //LOL!%0A  version: 'v1'%0A%7D);%0A%0Aapp.get('/synthesize', function(req, res) %7B%0A  var transcript = textToSpeech.synthesize(req.query);%0A%0A  transcript.on('response', function(response) %7B%0A    console.log(response.headers);%0A    if (req.query.download) %7B%0A      response.headers%5B'content-disposition'%5D = 'attachment; filename=transcript.ogg';%0A    %7D%0A  %7D);%0A  transcript.pipe(res);%0A%7D);%0A%0A//----- Ex
 ample 
-of 
+Sp
 each
- service.%0Avar services = JSON.parse(process.env.VCAP_SERVICES %7C%7C %22%7B%7D%22);%0A// TODO: Get service credentials and communicate with bluemix services.
+-%3EText from https://www.npmjs.com/package/watson-developer-cloud%0A// var params = %7B%0A//   // From file %0A//   audio: request('http://speech-to-text-demo.mybluemix.net/audio/sample1.wav'),%0A//   content_type: 'audio/l16; rate=44100'%0A// %7D;%0A// speech_to_text.recognize(params, function(err, res) %7B%0A//   if (err)%0A//     console.log(err);%0A//   else%0A//     console.log(JSON.stringify(res, null, 2));%0A// %7D);%0A%0A%0A//----- Example Text-%3ESpeach from https://www.npmjs.com/package/watson-developer-cloud%0A// var params = %7B%0A//     text: 'Hello from IBM Watson',%0A//     voice: 'VoiceEnUsMichael', // optional voice %0A//     accept: 'audio/wav'%0A// %7D;%0A// // pipe the synthesized text to a file %0A// text_to_speech.synthesize(params).pipe(fs.createWriteStream('output.wav'));%0A
 %0A%0A//

update server