Skip to content

Commit

Permalink
update frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiewq committed Jan 25, 2017
1 parent a8193eb commit a4c26fd
Show file tree
Hide file tree
Showing 10 changed files with 679 additions and 298 deletions.
34 changes: 25 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,36 @@ Fur Elise is a project aimed at translating digital music sheets to speech for t

#Deploy

Environment: node - v6.4.0, npm - v3.10.3

Get Node Version Manager:

```sh
$ curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh -o install_nvm.sh
$ bash install_nvm.sh
$ source ~/.profile
$ nvm install 6.4.0
$ nvm use 6.4.0
$ node -v //output v6.4.0
$ npm -v //output v3.10.3
```

Run front-end and text-to-speech service

```sh
cd path-to-fur-elise/frontend
npm install
$ cd path-to-fur-elise/frontend
$ npm install

cd path-to-fur-elise/frontend/app
bower install
$ cd path-to-fur-elise/frontend/app
$bower install

cd path-to-fur-elise/text2speech
npm install
node index.js
$ cd path-to-fur-elise/text2speech
$ npm install
$ node index.js

// Open a new terminal
cd path-to-fur-elise/frontend
npm start
$ cd path-to-fur-elise/frontend
$ npm start
// Web app will run at http://localhost:8000
```

Expand Down
10 changes: 10 additions & 0 deletions frontend/app/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
angular.module('myApp')
.service('config', [function() {
return {
api : {
text_to_speech : "http://localhost:8001",
music_score : "http://gameburning.com:5000/api",
user : "http://gameburning.com:5000/api"
}
};
}]);
2 changes: 2 additions & 0 deletions frontend/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<script src="bower_components/keymaster/keymaster.js"></script>
<script src="bower_components/howler/dist/howler.js"></script>
<script src="app.js"></script>
<script src="config.js"></script>
<script src="mainCtrl.js"></script>

<script src="directives/focus/focus.js"></script>
Expand All @@ -44,6 +45,7 @@
<script src="services/navigationService.js"></script>
<script src="services/httpUtil.js"></script>
<script src="services/fakeData.js"></script>
<script src="services/utility.js"></script>

</body>
</html>
92 changes: 92 additions & 0 deletions frontend/app/services/utility.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
angular.module('myApp')
.service('utility', ['httpUtil', '$q', 'config', function(httpUtil, $q, config) {
var self = this;

self.get_voice_by_text = function(text) {
var deferred = $q.defer();
httpUtil.get( config.api.text_to_speech + "/speak?sentence='"+ text +"'")
.then(function(response) {
if (response !== null) {
deferred.resolve(config.api.text_to_speech + response);
}
else {
deferred.reject({
err: "Ah!.. response is null",
status: 1
})
}
}, function(error) {
deferred.reject({
err: error,
status: 0
})
});
return deferred.promise;
}

self.get_voices_by_list = function(list) {
let promises = [];
var deferred = $q.defer();
for(var i = 0; i < list.length; i++) {
promises.push(httpUtil.get(config.api.text_to_speech + "/speak?sentence='"+list[i]+"'"));
}
$q.all(promises)
.then(function(values) {
for(var i = 0; i < values.length; i++) {
values[i] = config.api.text_to_speech + values[i];
}
deferred.resolve(values);
}, function(error){
deferred.reject({
err: error,
status: 0
})
});
return deferred.promise;
}

self.get_score = function(score_id) {
var deferred = $q.defer();
httpUtil.get(config.api.music_score + "/musicscores/" + score_id)
.then(function(response) {
if (response !== null) {
deferred.resolve(response);
}
else {
deferred.reject({
err: "Ah!.. response is null",
status: 1
})
}
}, function(error) {
deferred.reject({
err: error,
status: 0
})
});
return deferred.promise;
}

self.get_music_score_by_id = function(id) {
var deferred = $q.defer();
httpUtil.get( config.api.text_to_speech + "/speak?sentence='"+ text +"'")
.then(function(response) {
if (response !== null) {
deferred.resolve(config.api.text_to_speech + response);
}
else {
deferred.reject({
err: "Ah!.. response is null",
status: 1
})
}
}, function(error) {
deferred.reject({
err: error,
status: 0
})
});
return deferred.promise;
}

}]);
103 changes: 39 additions & 64 deletions frontend/app/views/favorite/favorite.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ angular.module('myApp.favorite', ['ngRoute'])
});
}])

.controller('FavoriteCtrl', ['$scope', 'httpUtil', 'fakeData', '$location', 'navigation',function($scope, httpUtil, fakeData, $location, navigation) {
.controller('FavoriteCtrl', ['$scope', 'httpUtil', 'fakeData', '$location', 'navigation','utility',
function($scope, httpUtil, fakeData, $location, navigation,utility) {
$scope.favoriteList = [];
$scope.selected = null;
$scope.showResult = false;
Expand All @@ -18,6 +19,13 @@ angular.module('myApp.favorite', ['ngRoute'])
key.unbind('right');
key.unbind('enter');

let active_sounds = [];
let stop_all_sounds = function() {
for(var i = 0; i < active_sounds.length; i++) {
active_sounds[i].stop();
}
}

var sound = new Howl({
src: ['/resources/sounds/viewFavorites.wav'],
preload: true,
Expand All @@ -38,27 +46,16 @@ angular.module('myApp.favorite', ['ngRoute'])
if($scope.favoriteList.length > 0) $scope.selected = 0;
$scope.showResult = true;
setTimeout(function(){
httpUtil.get("http://localhost:8001/speak?sentence='"+$scope.favoriteList[$scope.selected]+"'")
.then(function(response) {
//TODO: PUT ALL THESE CODE INTO "THEN"
// var response = fakeData.searchList; // TODO: Change to real API data

if (response !== null) {
//var snd = new Audio("http://localhost:8001" + response);
//snd.play();

var sound = new Howl({
src: ["http://localhost:8001" + response],
autoplay: true,
loop: false,
onend: function() {
console.log('Finished!');
}
});
}

}, function(error) {
});
utility.get_voice_by_text($scope.favoriteList[$scope.selected].name)
.then(function(sound_url){
var sound = new Howl({
src: [sound_url],
autoplay: true,
loop: false
});
}, function(error){

});
},1500);

}
Expand Down Expand Up @@ -86,27 +83,16 @@ angular.module('myApp.favorite', ['ngRoute'])
$scope.selected --;
$scope.$apply();
}
httpUtil.get("http://localhost:8001/speak?sentence='"+$scope.favoriteList[$scope.selected]+"'")
.then(function(response) {
//TODO: PUT ALL THESE CODE INTO "THEN"
// var response = fakeData.searchList; // TODO: Change to real API data

if (response !== null) {
//var snd = new Audio("http://localhost:8001" + response);
//snd.play();

var sound = new Howl({
src: ["http://localhost:8001" + response],
autoplay: true,
loop: false,
onend: function() {
console.log('Finished!');
}
});
}

}, function(error) {
});
utility.get_voice_by_text($scope.favoriteList[$scope.selected].name)
.then(function(sound_url){
var sound = new Howl({
src: [sound_url],
autoplay: true,
loop: false
});
}, function(error){

});
}
}

Expand All @@ -116,27 +102,16 @@ angular.module('myApp.favorite', ['ngRoute'])
$scope.selected ++;
$scope.$apply();
}
httpUtil.get("http://localhost:8001/speak?sentence='"+$scope.favoriteList[$scope.selected]+"'")
.then(function(response) {
//TODO: PUT ALL THESE CODE INTO "THEN"
// var response = fakeData.searchList; // TODO: Change to real API data

if (response !== null) {
//var snd = new Audio("http://localhost:8001" + response);
//snd.play();

var sound = new Howl({
src: ["http://localhost:8001" + response],
autoplay: true,
loop: false,
onend: function() {
console.log('Finished!');
}
});
}

}, function(error) {
});
utility.get_voice_by_text($scope.favoriteList[$scope.selected].name)
.then(function(sound_url){
var sound = new Howl({
src: [sound_url],
autoplay: true,
loop: false
});
}, function(error){

});
}
}

Expand Down
Loading

0 comments on commit a4c26fd

Please sign in to comment.