Comments (11)
Hi,can you post an example?
from google-translate-api.
Hi,can you post an example?
I did some digging, and I think it has to do with passing new line chars (\n). I am trying the exact same text (a full song) twice, once with the new line chars, one without. The one with new line chars took over 13 seconds, the one all in one line took 4 seconds. However, the new lines are important for me, to keep the same format.
This wasn't happening 2 days ago for some reason.
Here's my code:
const translate = require("google-translate-api-x");
export default async function translateFunc(req, res) {
console.log(JSON.stringify(prompt));
let data = await translate(
// New lines (very slow):
// "[Letra de Un violinista en tu tejado]\n\n[Verso 1]\nEre' tan dura como la piedra de mi mechero\nMe asaltan dudas de si te quiero\nEres tan fría, ay como el agua\nQue baja libre de la montaña\n\n[Pre-Estribillo]\nY no lo entiendo; fue tan efímero\nEl caminar de tu dedo en mi espalda dibujando un corazón\nY pido al cielo que sepa comprender\nEstos ataque' de celo' que me entran si yo no te vuelvo a ver\n\n[Estribillo]\nLe pido a la luna que alumbre tu vida\nLa mía hace ya tiempo que yace fundida\nCon lo que me cuesta querer sólo a rato'\nMejor no te quiero, será má' barato\nCansado de ser el triste violinista que está en tu tejado\nTocando pa'l inglé' siempre desafinao'\n\n[Verso 2]\nEres tan tenue como la luz que alumbra mi vida\nLa más madura fruta prohibida\nTan diferente y parecida\nA la tormenta que se llevó mi vida\n\n[Pre-Estribillo]\nY no lo entiendo; fue tan efímero\nEl caminar de tu dedo en mi espalda dibujando un corazón\nY pido al cielo que sepa comprender\nEstos ataque' de celo' que me entran si yo no te vuelvo a ver\n\n[Estribillo]\nLe pido a la luna que alumbre tu vida\nLa mía hace ya tiempo que yace fundida\nCon lo que me cuesta querer sólo a rato'\nMejor no te quiero, será má' barato\nCansado de ser el triste violinista que está en tu tejado\nTocando pa'l inglé' siempre desafinado\n\n[Solo]\n\n[Estribillo]\nLe pido a la luna que alumbre tu vida\nLa mía hace ya tiempo que yace fundida\nCon lo que me cuesta querer sólo a rato'\nMejor no te quiero, será má' barato\nCansado de ser el triste violinista que está en tu tejado\nTocando pa'l inglé' siempre desafinado y...\n\n[Verso 3 ]\nMientra' rebusco en tu basura\nNos van creciendo los enanos\nDe este un circo que un día montamos\nPero que no quepa duda\nMuy pronto estaré liberado\nPorque el tiempo todo lo cura\nPorque un clavo saca otro clavo\nSiempre desafinado, y...\nMientra' rebusco en tu basura\nNos van creciendo los enanos\nDe este circo que un día montamos\nPero que no quepa duda",
// Same text, without new line chars (much faster):
"[Letra de Un violinista en tu tejado] [Verso 1] Ere' tan dura como la piedra de mi mechero Me asaltan dudas de si te quiero Eres tan fría, ay como el agua Que baja libre de la montaña [Pre-Estribillo] Y no lo entiendo; fue tan efímero El caminar de tu dedo en mi espalda dibujando un corazón Y pido al cielo que sepa comprender Estos ataque' de celo' que me entran si yo no te vuelvo a ver [Estribillo] Le pido a la luna que alumbre tu vida La mía hace ya tiempo que yace fundida Con lo que me cuesta querer sólo a rato' Mejor no te quiero, será má' barato Cansado de ser el triste violinista que está en tu tejado Tocando pa'l inglé' siempre desafinao' [Verso 2] Eres tan tenue como la luz que alumbra mi vida La más madura fruta prohibida Tan diferente y parecida A la tormenta que se llevó mi vida [Pre-Estribillo] Y no lo entiendo; fue tan efímero El caminar de tu dedo en mi espalda dibujando un corazón Y pido al cielo que sepa comprender Estos ataque' de celo' que me entran si yo no te vuelvo a ver [Estribillo] Le pido a la luna que alumbre tu vida La mía hace ya tiempo que yace fundida Con lo que me cuesta querer sólo a rato' Mejor no te quiero, será má' barato Cansado de ser el triste violinista que está en tu tejado Tocando pa'l inglé' siempre desafinado [Solo] [Estribillo] Le pido a la luna que alumbre tu vida La mía hace ya tiempo que yace fundida Con lo que me cuesta querer sólo a rato' Mejor no te quiero, será má' barato Cansado de ser el triste violinista que está en tu tejado Tocando pa'l inglé' siempre desafinado y... [Verso 3 ] Mientra' rebusco en tu basura Nos van creciendo los enanos De este un circo que un día montamos Pero que no quepa duda Muy pronto estaré liberado Porque el tiempo todo lo cura Porque un clavo saca otro clavo Siempre desafinado, y... Mientra' rebusco en tu basura Nos van creciendo los enanos De este circo que un día montamos Pero que no quepa duda",
{
"English",
}
);
res.status(200).json({ translation: `${data.text}` });
}
Any thoughts would be much appreciated! Thanks so much!
from google-translate-api.
Since its only one block of text you can use the singleTranslate endpoint like what the vitalets package uses, enable it with these options {to: 'en', forceBatch: false}
FYI, your way of passing the to
language doesn't work, the only reason it is translating to English at all is because English is the default target language. You must do { to: "English" }
from google-translate-api.
Thanks for responding! I tried the forceBatch: false
command, but it's still giving the same result as before. I'm not sure why, any other ideas?
I realized the code I sent you was slightly different in my actual code (I changed that line for what I sent you to take out unnecessary variables I have), so it does have the to
command.
Thanks so much Aidan!
from google-translate-api.
When you try the same text/code, do you find the same issue, or do you think it's something wrong on my side? I'm trying to hone in on if it's my fault or something else. Thanks!
from google-translate-api.
Hi, yea I have the same issue when passing with forceBatch: true
(aka the default) but forceBatch: false
it resolves nearly instantly for both. You can also try fallbackBatch: false
but that shouldn't be relevant in this scenario other than for helping you find that you're ratelimited from the singleTranslate endpoint. Try forceBatch
and fallbackBatch
both false
and see if that returns an error. If not can you post your exact code, because I suspect you are actually passing a batch input (aka an array or object)- batch input requests can only be made to the batchTranslate endpoint.
from google-translate-api.
Ok, it seems to be working now! Thanks so much!
Quick other question I had, I'm trying to make flashcards, would it be good to use batch translate for that? Right now I'm doing a single translate, where it only translates the next 5 at a time when the user is on it/needs it.
Is batch much more efficient and good? Do you think instead of only translating 5 words separately when needed, with batch I could do many more?
Thanks!
from google-translate-api.
Depending on the number of individual requests batchTranslate I think is often better, especially because it is less likely to be rate limited. But, it is also sometimes less accurate.
from google-translate-api.
Thanks! Quick second question, do you have a transliteration feature? If so, can I use it in batch translate? Thanks!
from google-translate-api.
In a sense yes, on batch translates are the only ones where the Google translate API responds with "pronunciation" but it's not exactly transliteration.
from google-translate-api.
Closed for inactive
from google-translate-api.
Related Issues (20)
- Autocorrect not properly applied to translations from certain networks HOT 6
- Real-time translation HOT 2
- ReferenceError: fetch is not defined HOT 2
- TypeScript Error HOT 2
- requestOptions documentation outdated HOT 3
- It throws error "fetch is not defined" HOT 2
- Tests fail only because rate limited on single translate HOT 1
- TypeError: (0 , _googleTranslateApiX.translate) is not a function HOT 17
- google-translate-api-x gives below error HOT 3
- Improve `speak` testing
- Caught an error from batch translate HOT 8
- ERROR [TypeError: Cannot convert null value to object] HOT 2
- Issue with the speak functionality HOT 2
- Batch translation error HOT 4
- Can't run on React.js HOT 2
- change speak speed HOT 2
- fetch is not defined after deployment HOT 2
- CORS policy error HOT 4
- Obtain translation synonyms HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from google-translate-api.