Extract audio from Google translate - translate

Is it possible to extract the audio from the Google translate? check this link, for example:
http://translate.google.com/translate_tts?tl=en&q=%22choose%22
So if you click on this, it will give you back the word "choose". Is there a way to download that speech in some form of audio file?
Thanks

Actually was wondering about this myself, found this python script which can generate a mp3 file.
props go to original author ofcourse
https://github.com/hungtruong/Google-Translate-TTS/blob/master/GoogleTTS.py

The following seems to work (adapted from the link I posted above):
<?php
/**
* Initialize the cURL session
*/
$ch = curl_init();
/**
* Set the URL of the page or file to download.
*/
curl_setopt($ch, CURLOPT_URL,
'http://translate.google.com/translate_tts?tl=en&q=%22choose%22');
/**
* Create a new file
*/
$fp = fopen('audiofile', 'w');
/**
* Ask cURL to write the contents to a file
*/
curl_setopt($ch, CURLOPT_FILE, $fp);
/**
* Execute the cURL session
*/
curl_exec ($ch);
/**
* Close cURL session and file
*/
curl_close ($ch);
fclose($fp);
?>

You will find, that the solutions mentioned in 2014 don’t work anymore, as there is no mp3 file as a response, but a base64 encoded audio. For details see here:
https://github.com/Boudewijn26/gTTS-token/blob/master/docs/november-2020-translate-changes.md
You can get a simple command line interface for extracting/saving the audio with tihs project:
https://github.com/Boudewijn26/gTTS (Google Text to Speach)
With this you can just do:
gtts-cli 'hello' --output hello.mp3
and have your audio file.

Related

API CloudConvert curl request PHP

I would like to test a very simple case with the API CloudConvert with a curl request.
I want to import the file essaiFichier.txt with a curl request. I get a response in Json with a status "waiting". I have no idea if the request was well done. If someone has faced the same problem it would be great to have some
Below my code in order to fix the issue.
$authorization ="Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOi";
$url ="https://api.cloudconvert.com/v2/jobs";
$post = '{
"tasks": {
"import-1": {
"operation": "import/url",
"url": "http://localhost/biere/essaiFichier.txt",
"filename": "essaiFichier.txt"
}
}
}';
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , $authorization));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
I'm also new to cloudconvert, though it looks to me like you aren't following the 'rules' for using the service - at least, not to get anything useful out of it....
You need to do THREE things (at least):
Import (you have that)
Task (like 'convert'...)
Export (get your modified file back)
I find their 'Job Builder' to be a simple way to get the code - at least for starting out. See https://cloudconvert.com/api/v2/jobs/builder
I entered your 'Import' into the 'Job Builder' (note - I think you don't need the 'filename' in there, or you should break apart the 'url' and only have the file named in the 'filename' section - again, I'm new at it, but that is how I read it) and it still shows me this in the blue box at the top (the 'hints')
How to build a job
Add a processing task, for example a convert task.
Add an export task. You can use the export/url task to generate a URL for the output file.
Which tells me you just need to do the other parts so you have a complete request.
As for the 'waiting' response, yes, that is what you will get on the initial request. Again, see the docs on the Job Builder page - you can either do another request for the 'wait' response (which should get you the link for the 'export' part) or you can do a webhook that will be your trigger to download the file (which would make things more automatic).
Following your code and the Job Builder, I just finished my first conversion - worked great and now I can move on with my project (yeah!)
thank you very much for your complete and precise answer. Finally I found an alternative with https://github.com/dompdf/dompdf, wich is much easier to use for my opinion and without any inscription. I recommend it.
Thanks

Can't rename Google Drive files with nodeJs library

I'm unable to rename files in Google Drive in a NodeJs app. I'm using:
googleapi nodeJs library v. 20.1.0.
node v. 8.1.4
The app is handling requests for files fine, and it is able to duplicate files. However, when updating them, the new name is never applied.
I do get as a response the file resource, which would entail that the request was successful.
I'm doing this:
const google = require( 'googleapis' );
let googleService = google.drive( 'v3' );
let params = {
auth: testedAndValidOAuth,
fileId: validFileId,
uploadType: 'multipart',
name: "some name 2"
};
googleService.files.update( params, ( err, response ) => console.log(response));
For the property uploadType I've tried with and without it, with all the available options: resumable, multipart, and media. When trying media I got the following error:
Error: The API returned an error: Error: Uploads must be sent to the upload URL. Re-send this request to https://www.googleapis.com/upload/drive/v3/files/xxxfileIdxxx?uploadType=media&name=some+name+2
I've tried to edit manually the link in the library and the error went away, but unfortunately the name did not change.
Looking in the library I've noticed that the name param is not mentioned:
#param {object} params Parameters for request
#param {string=} params.addParents A comma-separated list of parent IDs to add.
#param {string} params.fileId The ID of the file.
#param {boolean=} params.keepRevisionForever Whether to set the 'keepForever' field in the new head revision. This is only applicable to files with binary content in Drive.
#param {string=} params.ocrLanguage A language hint for OCR processing during image import (ISO 639-1 code).
#param {string=} params.removeParents A comma-separated list of parent IDs to remove.
#param {boolean=} params.supportsTeamDrives Whether the requesting application supports Team Drives.
#param {boolean=} params.useContentAsIndexableText Whether to use the uploaded content as indexable text.
#param {object} params.resource Media resource metadata
#param {object} params.media Media object
#param {string} params.media.mimeType Media mime-type
#param {string|object} params.media.body Media body contents
#param {object} [options] Optionally override request options, such as `url`, `method`, and `encoding`.
#param {callback} callback The callback that handles the response.
So I'm wondering, am I doing something wrong, is this intended, meaning that we can't edit file names, or is it a bug in the library?
Try setting your new name in params.media.body, eg
params.resource = {name: "newname"}
corrected as per comment

Way to access ModX database by including ModX core file?

I have a PHP file (that I cant make a snippet out of). I need to connect it to the database and rather then doing it the normal way was wondering if I could just include a header file of some sort that already has a DB connection.
Does anyone know of such a file in the Modx file structure?
Easy...
if you open the main index.php, you can see some hint:
/* define this as true in another entry file, then include this file to simply access the API
* without executing the MODX request handler */
if (!defined('MODX_API_MODE')) {
define('MODX_API_MODE', false);
}
// ...
/* execute the request handler */
if (!MODX_API_MODE) {
$modx->handleRequest();
}
That said, if you have a raw PHP file, let's say as an example: hello.php
<?php
define('MODX_API_MODE', true); // IMPORTANT!!!
require 'index.php'; // or give directory path, according to your need
// let's test it
$startPage = $modx->getObject('modResource', $modx->getOption('site_start', null, 1));
if (!$startPage) {
die('CRAP!');
}
$startPageArray = $startPage->toArray();
echo '<pre>';
print_r($startPageArray);
echo '</pre>';
die('WOOHOO');
And no, you don't have to define $modx again.
It's using the same object in index.php.
you can run any operations against your modx database if you load the modx module in your external script [in fact you can use any modx functions]
https://rtfm.modx.com/revolution/2.x/developing-in-modx/other-development-resources/loading-modx-externally
once you instantiate the modx object it will handle all your database connection details. This will work in any page, not just manager pages.
The only place which allows database connections using system database config are manager pages, yet that would require more work to write a plugin to access its classes and functions.
If you want to be able to use MODX functionality to establish connection, I suggest using it's xPDO to perform queries, for security reasons at least.
Such setup would be:
define('MODX_CORE_PATH', '/path/to/revo/core/');
define('MODX_CONFIG_KEY','config');
require_once MODX_CORE_PATH . 'model/modx/modx.class.php';
$host = 'localhost';
$username = 'your_username';
$password = 'your_password';
$dbname = 'your_database';
$port = 3306;
$charset = 'utf-8';
$dsn = "mysql:host=$host;dbname=$dbname;port=$port;charset=$charset";
$xpdo = new xPDO($dsn, $username, $password);

Grails: How do I make my list a MS Excel file?

gsp is divided into two, the top part is like a search filter, and the bottom part is the regular list that is provided by Grails
I have a template _list.gsp in my list.gsp. And I wanna create a button to make that _list.gsp template a MS Excel file.
But I want only the template to be on the Excel file. Not the rest of the page
How can I do this in the simplest and direct way possible?? Thank you!
you can also take a look at the export plugin if you want to export the list to excel format
http://www.grails.org/plugin/export
Try this quite dirty trick in your index method:
response.setHeader( 'Content-Disposition', 'attachment;filename=list.xls' )
Explanation: the trick is that an HTML page renamed as *.xls can be read by office software suites. What you're doing is telling the browser to download a file with that name, instead of navigating to a regular HTML file. If you want to use this in a button, you should proceed as with any HTML generating page, and then add this header to the response. response is global to actions in Grails controllers.
All you need is to send search data to your controller, in the controller you can send content as explained by mschonaker, this is an example of what I did
def report = {
def reportType = params.report
....
.....
//Service class that collects data based on search data passed in params
def data = reportservice.execute(param)
//called export plugin to generate xls file
response.contentType = ConfigurationHolder.config.grails.mime.types[params.format]
response.setHeader("Content-disposition", "attachment; filename=${fileName}")
exportService.export(...)
}
Take a look at the Excel-export plugin. This has support for downloading only in .xlsx format. Exports an excel with the simplest coding.
I switched to this plugin from export plugin since had a clash with rendering plugin.
https://grails.org/plugin/excel-export
response.contentType = 'application/vnd.ms-excel'
response.setHeader("Content-disposition", "attachment; filename=OrderList.xlsx")
new WebXlsxExporter().with { //pass the contructor with "templateFileNameWithPath"
setResponseHeaders(response,new Date().format('dd-MM-yyyy_hh-mm')+"OrderList.xlsx")
fillHeader(labels)
add(data, fields)
save(response.outputStream)
}
response.outputStream.flush()
response.outputStream.close()}

Creating a script which helps present grades faster, and more efficiently

I am a high school student reasonably concerned about my grades, and when I check them through a system known as Zangle! Student Connection, it is mildly painful in how long it takes.
I was wondering if it would be possible to construct a script, in whichever language is deemed appropriate, to login for me, based on a pre-entered login username and password, and then present my grade percentages in a nice layout, instead of the kind of awkward and messy layout it is now presented in.
I'm guessing this either way to hard, or way out of my reach at the moment, or even impossible, but I just thought it was a decently cool idea and was looking for any suggestions.
Also, I have no idea as to which language is best for this, so I would definitely need help on this!
You could try Greasemonkey, it lets you create "user scripts" in Firefox. That way you could use Javascript to reorganise the interface.
Well, here is my take on it in PHP, utilizing the cURL library:
PHP is by no means deemed appropriate for the task. It is however, fairly easy to setup what you're looking for in the language.
<?php
error_reporting(-1);
$ch = curl_init();
/*Some sites block your access if you do not have cookies enabled. In order to get the cookies you will need to submit the form manually and using a packet sniffer (or Firebug) get the cookies that are being sent.*/
//$cookies ="CFID=25318504; CFTOKEN=38400766; PERSON_ID=3461047";
/*Again, if you have Firebug then getting the following POST data, once you submit the form manually, fairly straightforward. This is what cURL will utilize in the POST fields*/
//The action=submit may also vary, this is also easily acceible via Firebug. (right next to the parameters tab.
$post_data = "username=test&password=test&action=submit";
curl_setopt($ch, CURLOPT_URL, "http://www.sitename.com");
//follows a Location: redirect
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//send above cookies, which were gathered manually =(
//Utilize this only if cookies are a neccesity.
//curl_setopt($ch, CURLOPT_COOKIE, $cookies);
//Doing a POST request
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$output = curl_exec($ch);
curl_close($ch);
if($output == false) {
echo "cURL Error:" . curl_error($ch);
}
//You can sort this data using an HTML parser
echo $output;
Once you have successfully connected to the site, you can utilize one of many PHP HTML parsers to traverse through the data, such as: DOMDocument and Xpath or SimpleXML.

Resources