Browse Source

Delete voice

pull/126/head
Lal'C Mellk Mal 3 years ago
parent
commit
c80ea66eb8
5 changed files with 0 additions and 117 deletions
  1. +0
    -2
      config.js.example
  2. +0
    -2
      deps.js
  3. +0
    -2
      server/server.js
  4. +0
    -31
      voice/client.js
  5. +0
    -80
      voice/server.js

+ 0
- 2
config.js.example View File

@@ -48,8 +48,6 @@ var config = {
// API key with Youtube Data API v3 (browser) access
// obtain from https://console.developers.google.com
GOOGLE_API_KEY: '',

VOICE_PATH: 'voice',
};

module.exports = config;

+ 0
- 2
deps.js View File

@@ -32,7 +32,6 @@ exports.CLIENT_DEPS = [
'curfew/client.js',
'report/client.js',
'time/client.js',
'voice/client.js',
];

exports.SERVER_DEPS = [
@@ -72,7 +71,6 @@ exports.SERVER_DEPS = [
'server/web.js',
'time/server.js',
'tripcode/tripcode.cc',
'voice/server.js',
];

// Changes to these only require a state.js reload


+ 0
- 2
server/server.js View File

@@ -36,8 +36,6 @@ try {
require('../report/server');
} catch (e) {}
require('../time/server');
if (config.VOICE_PATH)
require('../voice/server');

var RES = STATE.resources;



+ 0
- 31
voice/client.js View File

@@ -1,31 +0,0 @@
(function () {

var eleven = /[\u4e00-\u9fbf\u3040-\u309f\u30a0-\u30ff]/;

oneeSama.hook('menuOptions', function (info) {
// TODO use model instead
if (!info.model)
return;
var text = $('#' + info.model.id).find('blockquote').text();
if (text && eleven.exec(text))
info.options.push('Speak');
});

menuHandlers.Speak = function (model) {
var $audio = $('<audio/>', {
src: model.id + '/voice',
attr: {autoplay: 'autoplay'},
});
var a = $audio[0];
if (a.canPlayType && !a.canPlayType('audio/mpeg;').replace(/no/, '')) {
alert("Can't play in this browser, sorry.");
return;
}
a.addEventListener('ended', function () {
$audio.remove();
}, false);
// TODO notify error
$audio.appendTo('body');
};

})();

+ 0
- 80
voice/server.js View File

@@ -1,80 +0,0 @@
var caps = require('../server/caps'),
config = require('../config');
crypto = require('crypto'),
db = require('../db'),
etc = require('../etc'),
fs = require('fs'),
imager = require('../imager'),
joinPath = require('path').join,
request = require('request'),
winston = require('winston'),
web = require('../server/web');
function tts(msg, dest, cb) {
msg = msg.slice(0, 100);
var query = {
q: msg,
tl: 'ja',
total: 1,
idx: 0,
textlen: msg.length,
ie: 'UTF-8',
};
var headers = {
Referer: "http://translate.google.com/",
'User-Agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.160 Safari/537.22",
};
var packet = {qs: query, encoding: null, headers: headers};
request('http://translate.google.com/translate_tts', packet,
function (err, resp, body) {
if (err)
return cb(err);
if (resp.statusCode != 200)
return cb(resp.statusCode || 500);
fs.writeFile(dest, body, cb);
});
}

web.resource(/^\/(\w+)\/(\d+)\/voice$/, function (req, params, cb) {
var board = params[1], num = parseInt(params[2], 10);
if (!num || !caps.can_access_board(req.ident, board))
return cb(404);
var op = db.OPs[num];
if (!op || !db.OP_has_tag(board, op))
return cb(404);
var yaku = new db.Yakusoku(null, req.ident);
yaku.get_current_body(num, function (err, body, isFinal) {
if (err)
return cb(err);
body = body && body.trim().slice(0, 100);
if (!body)
return cb(etc.Muggle("No text."));

var MD5 = crypto.createHash('md5').update(body).digest('hex');
var MP3 = 'v' + imager.squish_MD5(MD5) + '.mp3';
var path = joinPath(config.VOICE_PATH, MP3);
var context = {path: path, temp: !isFinal};
fs.exists(path, function (exists) {
if (exists)
return cb(null, 'ok', context);
tts(body, path, function (err) {
if (err)
return cb(err);
cb(null, 'ok', context);
});
});
});
},
function (req, resp) {
resp.writeHead(200, {
'Content-Type': 'audio/mpeg',
'Cache-Control': this.temp ? 'no-cache' : 'max-age=600000',
});
var stream = fs.createReadStream(this.path);
stream.pipe(resp);
stream.once('error', function (err) {
winston.error(err);
resp.end();
});
});

Loading…
Cancel
Save