logo
down
shadow

Should an extracted audio sample be contained inside its original source when comparing bytes?


Should an extracted audio sample be contained inside its original source when comparing bytes?

By : Renee
Date : November 17 2020, 11:52 AM
I wish this help you Let's say that I have an audio wav file with the sentence: , @Phil, you are the guy! Your tips led me to the solution!
code :
private int compare(byte[] captchaData, byte[] sampleData) throws IOException {
    return new String(captchaData).indexOf(new String(sampleData));
}

private byte[] transform(Path audio) throws IOException, UnsupportedAudioFileException {
    AudioInputStream ais = AudioSystem.getAudioInputStream(audio.toFile());
    AudioFormat format = ais.getFormat();
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
        int nBufferSize = 1024 * format.getFrameSize();
        byte[] abBuffer = new byte[nBufferSize];
        int nBytesRead;
        while ((nBytesRead = ais.read(abBuffer)) > -1) {
            baos.write(abBuffer, 0, nBytesRead);
        }
        return baos.toByteArray();
    }
}
private List<byte[]> split(byte[] audioData) {
    System.out.println(audioData.length);
    List<byte[]> byteList = new ArrayList<>();
    int zeroCounter = 0;
    int lastPos = 0;
    for (int i = 0; i < audioData.length; i++) {
        if (audioData[i] >= -1 && audioData[i] <= 1) {
            zeroCounter++; //too many leading 'zeros' could indicate silence or very low noise...
        } else if (zeroCounter > 0) {
            if (zeroCounter > 2000) {
                int from = lastPos;
                int to = i - (zeroCounter/2);
                byteList.add(
                    Arrays.copyOfRange(
                        audioData,
                        from,
                        to));
                System.out.println("split from: " + from + " to: " + to);
                lastPos = to;
            }
            zeroCounter = 0;
        }
    }
    return byteList;
}


Share : facebook icon twitter icon
obtaining an AudioInputStream upto some x bytes from the original (Cutting an Audio File)

obtaining an AudioInputStream upto some x bytes from the original (Cutting an Audio File)


By : user3572613
Date : March 29 2020, 07:55 AM
Does that help The code below shows you how to copy a part of an audio stream, reading from one file and writing to another.
code :
import java.io.*;
import javax.sound.sampled.*;

class AudioFileProcessor {

  public static void main(String[] args) {
    copyAudio("/tmp/uke.wav", "/tmp/uke-shortened.wav", 2, 1);
  }

  public static void copyAudio(String sourceFileName, String destinationFileName, int startSecond, int secondsToCopy) {
    AudioInputStream inputStream = null;
    AudioInputStream shortenedStream = null;
    try {
      File file = new File(sourceFileName);
      AudioFileFormat fileFormat = AudioSystem.getAudioFileFormat(file);
      AudioFormat format = fileFormat.getFormat();
      inputStream = AudioSystem.getAudioInputStream(file);
      int bytesPerSecond = format.getFrameSize() * (int)format.getFrameRate();
      inputStream.skip(startSecond * bytesPerSecond);
      long framesOfAudioToCopy = secondsToCopy * (int)format.getFrameRate();
      shortenedStream = new AudioInputStream(inputStream, format, framesOfAudioToCopy);
      File destinationFile = new File(destinationFileName);
      AudioSystem.write(shortenedStream, fileFormat.getType(), destinationFile);
    } catch (Exception e) {
      println(e);
    } finally {
      if (inputStream != null) try { inputStream.close(); } catch (Exception e) { println(e); }
      if (shortenedStream != null) try { shortenedStream.close(); } catch (Exception e) { println(e); }
    }
  }

  public static void println(Object o) {
    System.out.println(o);
  }

  public static void print(Object o) {
    System.out.print(o);
  }

}
What is the proper way to represent an audio sample in two bytes?

What is the proper way to represent an audio sample in two bytes?


By : user3213951
Date : March 29 2020, 07:55 AM
wish of those help Since sine has a limited range [-1.0, 1.0], you can map the value from that range to the range of 16-bit integers [-32768, 32767].
code :
short sample_short = SHORT_MAX * sample;
result = DST_TYPE_MAX * original / ORIGINAL_MAX;
result = DST_TYPE_MAX * (original - ORIGINAL_MIN) / (ORIGINAL_MAX-ORIGINAL_MIN)
HTML5 audio element with source being audio stored as varbinary bytes from database

HTML5 audio element with source being audio stored as varbinary bytes from database


By : Jan Dreher
Date : March 29 2020, 07:55 AM
wish helps you I was able to get the answer to this question by asking another slighty different but nonetheless the same question.
https://stackoverflow.com/a/32904927/5179424
Why is the size of audio sample in mdat atom of mp4 file more than 300 bytes?

Why is the size of audio sample in mdat atom of mp4 file more than 300 bytes?


By : Alex Denysenko
Date : March 29 2020, 07:55 AM
To fix this issue Your are trying to find out why the encoded AAC frame size is around 370?
Sampling rate = 44100 [pcm samples/sec]
What do sample bytes in raw audio files mean?

What do sample bytes in raw audio files mean?


By : Ramazan GS Abdullaye
Date : March 29 2020, 07:55 AM
wish of those help If you visualize a sound wave, it is a curve in form of a line. And as we all know, a line consists out of infinite points. Since a hard drive is limited in space, it can't store infinite points. It just can store a few points. So what can we do? We just take out a few points of this "line" and store them. And each of these points is a sample. It is the displacement of the audio wave at a specific time. So if you've got a sound like this:
Related Posts Related Posts :
  • Stream corrupted exception - invalid code type AC [java]
  • Routing Sysout values to JTextArea
  • GWT RPC serialization for Dynamic Host Page
  • Best Approch of Returning Value from 'getter' Method
  • Understanding xml schemalocation
  • Checking if a PDF is PDF/A 1-a format or not using PDFBOX in java
  • Difference Between Variable and Identifier
  • How to compute two aggregate functions with Java streams?
  • Parse the value of the json to baseadapter in android?
  • JavaFX animation on raspberry pi
  • Solve "unchecked warning" in Java avoiding @suppressWarnings
  • How to specify a new name for a file while moving it to another directory in Java?
  • Popup window not showing up with spinner item selection?
  • how to iterate through json objects in java
  • Caused by: java.lang.NoClassDefFoundError: org/springframework/aop/framework/AbstractAdvisingBeanPostProcessor
  • Getting NoClassDefFoundError while running PMD task from Gradle
  • Matlab drag and drop file from windows explorer to figure (gui)
  • How does scala's actor model make use of C threads and native system threads?
  • Store java.util.Date as key in a Map based on reference equality instead of "value" equality
  • Error when logging into FTP from AsyncTask class using org.apache.commons.net.ftp.FTPClient
  • creating unique index in mongoDB
  • hibernate Query to find record based on substring
  • How many strings are in jvm string pool intern
  • Unable to initialize native-platform. on Jenkins
  • How to create a list of dummy files in Java?
  • Docker: Which approach is better? WAR embedded in image or base image + war?
  • java.lang.InternalError: CallerSensitive annotation expected at frame 1
  • How to write a method to read JSON files of different structures and return different POJO objects in Java?
  • Reference to Classes in Java
  • Unable to call function via companion object
  • REST: convert XML content passed with POST to a java object, attribute inside the element
  • Device not receive message from GCM
  • How to increase Openfire concurrent connection limit?
  • Android send custom parameter on AsyncTask
  • GWT - Get dom element's value from another page
  • How can i initialize an array in Java?
  • Is it possible to increase a java process's(when is running) size?
  • Getting Node Address instead of Value in Binary Search Tree
  • PdfByteContent not adding in iText pdf
  • Spring JpaRepository: delete() with subsequent save() in the same transaction
  • producer-consumer using arraydeque working only in breakpoint
  • Adding a JPanel to another JPanel
  • Comparison with operator ==, how does it work?
  • Error buildling with maven for openshift
  • What is the java equivilant to MySQL's smallint
  • proxy trouble on eclipse with https
  • Spring-Jdbc Template and Prepared statement
  • Mule - exception in Outbound endpoint Message payload is of type: byte[]
  • Modify package names for java classes generated from wsdl
  • How to download multiple images and have one progressBar using AsynTask (Android)
  • Implementing Service Provider, IdP and user in java with SAML (POC)
  • Why does my scanner repeat?
  • Can I forget ResultSetFuture in Cassandra java driver without facing memory leak?
  • XML to JAXB binding having nested elements?
  • Java: ToString() prints the same hashcode each time
  • Why am I getting a thread exception in my graphics program?
  • Can we read 4th byte from hexadecimal value?
  • How to create watermark in image just like Google maps watermarks
  • how come Thread class called inside another class?
  • AssertionError: Unexpected schema version 0: Unexpected schema version 0
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org