-
Notifications
You must be signed in to change notification settings - Fork 65
Code settings for 16 KHZ MONO 256 bit rate audio #26
Copy link
Copy link
Open
Description
Dear Sir,
I have am recording PCM 16 BIT audio using Android at Sample rate of 16000 . Now i have raw PCM Audio.
For this case what should be the value of the variables
OpusEncoder encoder = new OpusEncoder(16000, 1, OpusApplication.OPUS_APPLICATION_VOIP);
encoder.setBitrate(32000);
int packetSamples = 960;
I have set the above values however when i listen to the OPUS audio it is playing at a very faster speed. What am i doing wrong.
I am converting it using the sample code provided.
public static void main(File fin, File fout) {
try {
FileInputStream fileIn = new FileInputStream(fin);
OpusEncoder encoder = new OpusEncoder(16000, 1, OpusApplication.OPUS_APPLICATION_VOIP);
encoder.setBitrate(32000);
encoder.setSignalType(OpusSignal.OPUS_SIGNAL_VOICE);
encoder.setComplexity(0);
FileOutputStream fileOut = new FileOutputStream(fout);
OpusInfo info = new OpusInfo();
info.setNumChannels(1);
info.setSampleRate(16000);
OpusTags tags = new OpusTags();
//tags.setVendor("Concentus");
//tags.addComment("title", "A test!");
OpusFile file = new OpusFile(fileOut, info, tags);
int packetSamples = 960;
byte[] inBuf = new byte[packetSamples * 2 * 2];
byte[] data_packet = new byte[1275];
long start = System.currentTimeMillis();
while (fileIn.available() >= inBuf.length) {
int bytesRead = fileIn.read(inBuf, 0, inBuf.length);
short[] pcm = BytesToShorts(inBuf, 0, inBuf.length);
int bytesEncoded = encoder.encode(pcm, 0, packetSamples, data_packet, 0, 1275);
byte[] packet = new byte[bytesEncoded];
System.arraycopy(data_packet, 0, packet, 0, bytesEncoded);
OpusAudioData data = new OpusAudioData(packet);
file.writeAudioData(data);
}
file.close();
long end = System.currentTimeMillis();
System.out.println("Time was " + (end - start) + "ms");
fileIn.close();
//fileOut.close();
System.out.println("Done!");
} catch (IOException e) {
System.out.println(e.getMessage());
} catch (OpusException e) {
System.out.println(e.getMessage());
}
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels