- Common ways to obtain AudioFormat
private void myMethod () {AudioFormat a =
String str;new AudioFormat(str)
String str;new AudioFormat(str, double1, int1, int2)
- Smart code suggestions by Codota
}
/** * Get the length of the audio in this {@link TranscriptionRequest} in * milliseconds * * @return the duration of the audio in milliseconds or -1 when unknown */ public long getDurationInMs() { if(this.format == null) { return -1; } return TimeUnit.NANOSECONDS.toMillis( this.format.computeDuration(this.audio.length)); }
/** * Gets the length in milliseconds of the media in a specific * <tt>Buffer</tt> (often referred to as duration). * * @param buffer the <tt>Buffer</tt> which contains media the length in * milliseconds of which is to be calculated * @return the length in milliseconds of the media in <tt>buffer</tt> if * there actually is media in <tt>buffer</tt> and its length in milliseconds * can be calculated; otherwise, <tt>0</tt> */ private long getLengthInMillis(Buffer buffer) { int length = buffer.getLength(); if (length < 1) return 0; Format format = buffer.getFormat(); if (format == null) { format = getFormat(); if (format == null) return 0; } if (!(format instanceof AudioFormat)) return 0; AudioFormat audioFormat = (AudioFormat) format; long duration = audioFormat.computeDuration(length); return (duration < 1) ? 0 : (duration / 1000000); }
= (audioStreamFormat.computeDuration(audioStreamLength) + 999999) / 1000000;