Reputation: 83
I'm working on making a private dictionary & need some help saving the Mp3 file grabbed using Google's TTS API. I've looked around Google & Stack, all I can find is something slightly related in python. I'm not too good with python which is why I prefer java in this situation. If anyone has some pointers on just saving the Mp3 to the project directory (nothing special). If anyone knows what they're doing when it comes to saving the inputstream as an MP3 any tips will be appreaciated, Thanks!
Upvotes: 0
Views: 1174
Reputation: 1609
Wrote this way back - https://github.com/raynaya/Tts-using-google-translate/blob/master/web/convert.jsp
take a look at this part
String string=request.getParameter("a");
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet("http://translate.google.com/translate_tts?tl=en&q="+string);
HttpResponse res = httpclient.execute(httpget);
HttpEntity entity = res.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
OutputStream t = new FileOutputStream(new File("C:\\Documents and Settings\\shamik\\My Documents\\NetBeansProjects\\freetts\\web\\resources\\newfile.mp3"));
int l;
byte[] tmp = new byte[2048];
while ((l = instream.read(tmp)) != -1) {
t.write(tmp, 0, l);
}
instream.close();
t.flush();
t.close();
This should help
Upvotes: 1