diff --git a/index.js b/index.js index 108cb70..5a3cf2a 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,3 @@ -var key = require('./lib/key'); var tts = require('./lib/api'); /** @@ -7,11 +6,8 @@ var tts = require('./lib/api'); * @param {String} text * @param {String!} lang default is 'en' * @param {Number!} speed default is 1, show = 0.24 - * @param {Number!} timeout default is 10000ms * @return Promise(url: String) */ -module.exports = function (text, lang, speed, timeout) { - return key(timeout).then(function (key) { - return tts(text, key, lang, speed); - }); +module.exports = function (text, lang, speed) { + return tts(text, lang, speed); }; diff --git a/lib/api.js b/lib/api.js index 9514a28..8d4c931 100644 --- a/lib/api.js +++ b/lib/api.js @@ -1,5 +1,4 @@ var url = require('url'); -var token = require('./token'); var host = 'https://translate.google.com'; /** @@ -11,7 +10,7 @@ var host = 'https://translate.google.com'; * @param {Number!} speed show = 0.24, default is 1 * @return {String} url */ -module.exports = function (text, key, lang, speed) { +module.exports = function (text, lang, speed) { if (typeof text !== 'string' || text.length === 0) { throw new TypeError('text should be a string'); } @@ -20,10 +19,6 @@ module.exports = function (text, key, lang, speed) { throw new RangeError('text length (' + text.length + ') should be less than 200 characters'); } - if (typeof key !== 'string' || key.length === 0) { - throw new TypeError('key should be a string'); - } - if (typeof lang !== 'undefined' && (typeof lang !== 'string' || lang.length === 0)) { throw new TypeError('lang should be a string'); } @@ -40,8 +35,7 @@ module.exports = function (text, key, lang, speed) { total: 1, idx: 0, textlen: text.length, - tk: token(text, key), - client: 't', + client: 'tw-ob', prev: 'input', ttsspeed: speed || 1 } diff --git a/package-lock.json b/package-lock.json index d62a68d..10c4cd1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "google-tts-api", - "version": "0.0.4", + "version": "0.0.5", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/test/long-characters.test.js b/test/long-characters.test.js index 7ec2269..d2a9e41 100644 --- a/test/long-characters.test.js +++ b/test/long-characters.test.js @@ -8,7 +8,7 @@ describe('Long Characters', () => { 'The Industrial Revolution had several roots, one of which was a commercial revolution that, beginnin' + 'g as far back as the sixteenth century, accompanied Europe’s expansion overseas.'; - const url = await tts(text, 'en'); + const url = tts(text, 'en'); const res = await fetch(url); expect(res.status).toBe(200); }); @@ -18,7 +18,7 @@ describe('Long Characters', () => { 'The Industrial Revolution had several roots, one of which was a commercial revolution that, beginnin' + 'g as far back as the sixteenth century, accompanied Europe’s expansion overseas. exports and imports'; - const url = await tts(text, 'en'); + const url = tts(text, 'en'); const res = await fetch(url); expect(res.status).toBe(200); }); @@ -29,7 +29,9 @@ describe('Long Characters', () => { 'g as far back as the sixteenth century, accompanied Europe’s expansion overseas. Both exports and im' + 'ports showed spectacular growth, particularly in England and France.'; - await expect(tts(text, 'en')).rejects.toThrow('should be less than 200 characters'); + expect(()=>{ + tts(text, 'en'); + }).toThrow('should be less than 200 characters'); }); it('Chinese: 193 characters', async () => { @@ -39,7 +41,7 @@ describe('Long Characters', () => { '可以迅速被沉积物掩埋的地方,摆脱被完全摧毁的几率便会大大增加。海底通常就具有上述的两方面条件,这里生' + '活着很多带壳的无脊椎动物(没有脊椎的动物),不断累积的似雨的沉积颗粒会把它们掩埋起来。'; - const url = await tts(text, 'zh'); + const url = tts(text, 'zh'); const res = await fetch(url); expect(res.status).toBe(200); }); @@ -51,7 +53,7 @@ describe('Long Characters', () => { '可以迅速被沉积物掩埋的地方,摆脱被完全摧毁的几率便会大大增加。海底通常就具有上述的两方面条件,这里生' + '活着很多带壳的无脊椎动物(没有脊椎的动物),不断累积的似雨的沉积颗粒会把它们掩埋起来。虽然多数的化石'; - const url = await tts(text, 'zh'); + const url = tts(text, 'zh'); const res = await fetch(url); expect(res.status).toBe(200); }); @@ -64,6 +66,8 @@ describe('Long Characters', () => { '活着很多带壳的无脊椎动物(没有脊椎的动物),不断累积的似雨的沉积颗粒会把它们掩埋起来。虽然多数的化石' + '是在海洋沉积岩中发现的'; - await expect(tts(text, 'zh')).rejects.toThrow('should be less than 200 characters'); + expect(()=>{ + tts(text, 'zh'); + }).toThrow('should be less than 200 characters'); }); }); diff --git a/test/param.test.js b/test/param.test.js index 2a087ce..207a994 100644 --- a/test/param.test.js +++ b/test/param.test.js @@ -2,39 +2,35 @@ const tts = require('..'); jest.setTimeout(60000); describe('parameters', () => { - it('text = null', async () => { - await expect(tts(null)).rejects.toThrow('text should be a string'); + it('text = null', () => { + expect(()=>{tts(null);}).toThrow('text should be a string'); }); - it("text = ''", async () => { - await expect(tts('')).rejects.toThrow('text should be a string'); + it("text = ''", () => { + expect(()=>{tts('');}).toThrow('text should be a string'); }); - it('text = 123', async () => { - await expect(tts(123)).rejects.toThrow('text should be a string'); + it('text = 123', () => { + expect(()=>{tts(123);}).toThrow('text should be a string'); }); - it('lang = null', async () => { - await expect(tts('test', null)).rejects.toThrow('lang should be a string'); + it('lang = null', () => { + expect(()=>{tts('test', null);}).toThrow('lang should be a string'); }); - it("lang = ''", async () => { - await expect(tts('test', '')).rejects.toThrow('lang should be a string'); + it("lang = ''", () => { + expect(()=>{tts('test', '');}).toThrow('lang should be a string'); }); - it('lang = 123 (number)', async () => { - await expect(tts('test', 123)).rejects.toThrow('lang should be a string'); + it('lang = 123 (number)', () => { + expect(()=>{tts('test', 123);}).toThrow('lang should be a string'); }); - it('speed = null', async () => { - await expect(tts('test', 'en', null)).rejects.toThrow('speed should be a number'); + it('speed = null', () => { + expect(()=>{tts('test', 'en', null);}).toThrow('speed should be a number'); }); - it("speed = '123'", async () => { - await expect(tts('test', 'en', '123')).rejects.toThrow('speed should be a number'); - }); - - it('timeout = 10 ms (too short to success)', async () => { - await expect(tts('test', 'en', 1, 10)).rejects.toThrow('network timeout'); + it("speed = '123'", () => { + expect(()=>{tts('test', 'en', '123');}).toThrow('speed should be a number'); }); });