2

I tried lame mp3 encoder in android to convert a wav file to mp3, libmp3lame.so was generated and the app convert test.wav to test.mp3 successfully but the problem is that the mp3 file is like THIS, my wav file is a voice of speaking and when it converts nothing can be understand, what is the problem? is it becuase of mp3 options or not?

Here is my main code:

public class Main extends Activity {

static {
    System.loadLibrary("mp3lame");
}

private native void initEncoder(int numChannels, int sampleRate,
        int bitRate, int mode, int quality);

private native void destroyEncoder();

private native int encodeFile(String sourcePath, String targetPath);

public static final int NUM_CHANNELS = 1;
public static final int SAMPLE_RATE = 16000;
public static final int BITRATE = 128;
public static final int MODE = 1;
public static final int QUALITY = 2;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    initEncoder(NUM_CHANNELS, SAMPLE_RATE, BITRATE, MODE, QUALITY);

    encodeFile(Environment.getExternalStorageDirectory()
            .getPath() + "/test.wav", Environment
            .getExternalStorageDirectory().getPath() + "/test.mp3")
}

@Override
public void onDestroy() {
    destroyEncoder();
    super.onDestroy();
}

}

1 Answers1

0

We convert with php in windows and the ffmpeg.exe from MediaHuman, which also makes a backup of the original.

<?php

ini_set('display_errors', 1);
const SAMPLERATE = 44100;
const BITRATE = 128;
const CHANNELS = 2;
$dir = 'newmusic';

include('ID3TagsReader.php');

function needsConversion($file) {
$reader = new ID3TagsReader();
$headers = $reader->getMP3BitRateSampleRate($file);

if($headers['sampleRate'] != SAMPLERATE) return true;
if($headers['bitRate'] != BITRATE) return true;

return false;
}

function backupFile($file) {
$source = $file;
$dest = "C:\\backup\\music\\" . $file . " - "  . date('YmdHis') . ".mp3";

echo "Copying $source to $dest\n";
copy($source, $dest);
}

function convertFile($file) {
    echo "Converting file " . $file . "\n";

    $ffmpeg = escapeshellarg("C:\\Program Files\\MediaHuman\\Audio 
Converter\\ffmpeg.exe");
    $source = escapeshellarg($file);
    $samplerate = escapeshellarg(SAMPLERATE);
    $bitrate = escapeshellarg(BITRATE * 1000);
    $channels = escapeshellarg(CHANNELS);

    echo system("$ffmpeg -i $source -ar $samplerate -ac $channels -ab $bitrate -y 
temp.mp3 2>&1");

    rename('temp.mp3', $file);
}

chdir($dir);
foreach(glob('*.mp3') as $file) {
if(needsConversion($file)) {
    backupFile($file);
    convertFile($file);
}
}

header('Location: some place to go');
?>