<commit_before>package com.ibm.watson.developer_cloud.android.library.audio;

import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioTrack;
import android.util.Log;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Exposes the ability to play raw audio data from an InputStream
 */
public final class StreamPlayer {
  private final String TAG = "StreamPlayer";

  private AudioTrack audioTrack;
  private int sampleRate;

  /**
   * Play the given InputStream
   */
  public void playStream(InputStream stream) {
    try {
      byte[] data = convertStreamToByteArray(stream);
      if (data.length > 28) {
        sampleRate = readInt(data, 24);
      }
      int headSize = 44, metaDataSize = 48;
      int destPos = headSize + metaDataSize;
      int rawLength = data.length - destPos;
      byte[] d = new byte[rawLength];
      System.arraycopy(data, destPos, d, 0, rawLength);
      initPlayer();
      audioTrack.write(d, 0, d.length);
      stream.close();
      if (audioTrack != null && audioTrack.getState() != AudioTrack.STATE_UNINITIALIZED) {
        audioTrack.release();
      }
    } catch (IOException e2) {
      Log.e(TAG, e2.getMessage());
    }
  }

  /**
   * Initialize AudioTrack by getting buffersize<commit_msg>Expose a method to interrupt an audio stream<commit_after>package com.ibm.watson.developer_cloud.android.library.audio;

import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioTrack;
import android.util.Log;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Exposes the ability to play raw audio data from an InputStream
 */
public final class StreamPlayer {
  private final String TAG = "StreamPlayer";

  private AudioTrack audioTrack;
  private int sampleRate;

  /**
   * Play the given InputStream
   */
  public void playStream(InputStream stream) {
    try {
      byte[] data = convertStreamToByteArray(stream);
      if (data.length > 28) {
        sampleRate = readInt(data, 24);
      }
      int headSize = 44, metaDataSize = 48;
      int destPos = headSize + metaDataSize;
      int rawLength = data.length - destPos;
      byte[] d = new byte[rawLength];
      System.arraycopy(data, destPos, d, 0, rawLength);
      initPlayer();
      audioTrack.write(d, 0, d.length);
      stream.close();
      if (audioTrack != null && audioTrack.getState() != AudioTrack.STATE_UNINITIALIZED) {
        audioTrack.release();
      }
    } catch (IOException e2) {
      Log.e(TAG, e2.getMessage());
    }
  }

  /**
   * Interrupt the audioStream
   */
  public void interrupt() {
    if (audioTrack != null) {
      audioTrack.flush();
      audioTrack.stop();
      audioTrack.release();
    }
  }

  /**
   * Initialize AudioTrack by getting buffersize
{'fraction_non_alphanumeric': 0.1111111111111111, 'fraction_numerical': 0.008333333333333333, 'mean_word_length': 3.1157142857142857, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6022124', 'n_tokens_mistral': 876, 'n_tokens_neox': 841, 'n_words': 224}