Java URL to convertUrlToMp3Cmd(final String url)

Here you can find the source of convertUrlToMp3Cmd(final String url)

Description

convert Url To Mp Cmd

License

Apache License

Declaration

public static File convertUrlToMp3Cmd(final String url) throws IOException, InterruptedException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URLEncoder;
import java.util.UUID;

public class Main {
    public static File convertUrlToMp3Cmd(final String url) throws IOException, InterruptedException {
        final String mp3Filename = UUID.randomUUID().toString() + ".mp3";
        final String escFilename = URLEncoder.encode(url.substring(url.lastIndexOf("/") + 1), "UTF-8");
        final String escUrl = url.substring(0, url.lastIndexOf("/") + 1) + escFilename;
        // ffmpeg -i https://s3.amazonaws.com/io.klerch.alexa.translator/en-GB/Marlene/good_morning.mp3 -ac 2 -codec:a libmp3lame -b:a 48k -ar 16000 -af volume=10dB sample.mp3
        final String cmd = "ffmpeg -i " + escUrl + " -ac 2 -codec:a libmp3lame -b:a 48k -ar 16000 -af volume=10dB "
                + mp3Filename;/* www .  jav  a 2s  .  co  m*/
        System.out.println(cmd);
        final Process p = Runtime.getRuntime().exec(cmd);
        p.waitFor();

        final BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));

        String line = "";
        while ((line = reader.readLine()) != null) {
            System.out.println(line);
        }
        return new File(mp3Filename);
    }
}

Related

  1. convertURL(String url)
  2. convertURLToFile(URL url)
  3. convertUrlToFilename(URL url)
  4. convertUrlToFilePath(URL url)
  5. convertUrlToHostNameAsNodeName(String url)
  6. copyUrlToFile(URL url, File file)
  7. copyUrlToFile(URL url, File file)