当前位置: 首页>>代码示例>>Java>>正文


Java AudioRecord.release方法代码示例

本文整理汇总了Java中android.media.AudioRecord.release方法的典型用法代码示例。如果您正苦于以下问题:Java AudioRecord.release方法的具体用法?Java AudioRecord.release怎么用?Java AudioRecord.release使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.media.AudioRecord的用法示例。


在下文中一共展示了AudioRecord.release方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createAudioRecord

import android.media.AudioRecord; //导入方法依赖的package包/类
/**
 * Creates a new {@link AudioRecord}.
 *
 * @return A newly created {@link AudioRecord}, or null if it cannot be created (missing
 * permissions?).
 */
private AudioRecord createAudioRecord() {
    for (int sampleRate : SAMPLE_RATE_CANDIDATES) {
        final int sizeInBytes = AudioRecord.getMinBufferSize(sampleRate, CHANNEL, ENCODING);
        if (sizeInBytes == AudioRecord.ERROR_BAD_VALUE) {
            continue;
        }
        final AudioRecord audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC,
                sampleRate, CHANNEL, ENCODING, sizeInBytes);
        if (audioRecord.getState() == AudioRecord.STATE_INITIALIZED) {
            mBuffer = new byte[sizeInBytes];
            return audioRecord;
        } else {
            audioRecord.release();
        }
    }
    return null;
}
 
开发者ID:hsavaliya,项目名称:GoogleAssistantSDK,代码行数:24,代码来源:VoiceRecorder_.java

示例2: RecognizerThread

import android.media.AudioRecord; //导入方法依赖的package包/类
public RecognizerThread(int timeout) {
    if (timeout != NO_TIMEOUT) {
        this.timeoutSamples = timeout * sampleRate / 1000;
    } else {
        this.timeoutSamples = NO_TIMEOUT;
    }
    this.remainingSamples = this.timeoutSamples;
    recorder = new AudioRecord(6, sampleRate, 16, 2, bufferSize * 2);
    if (recorder.getState() == AudioRecord.STATE_UNINITIALIZED) {
        recorder.release();
        try {
            throw new IOException(
                    "Failed to initialize recorder. Microphone might be already in use.");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:icaksama,项目名称:RapidSphinx,代码行数:19,代码来源:RapidRecognizer.java

示例3: run

import android.media.AudioRecord; //导入方法依赖的package包/类
@Override
public void run() {
    byte[] buffer = new byte[audioBufferSize];
    recorder = new AudioRecord(audioSource, sampleRate, channel, audioFormat, audioBufferSize);
    try {
        while (recorder.getState() != AudioRecord.STATE_INITIALIZED)
            Thread.sleep(100, 0);
    } catch (InterruptedException e) {
        recorder.release();
        return;
    }

    recorder.startRecording();
    for (; ; ) {
        int length = recorder.read(buffer, 0, buffer.length);
        if (length < 0)
            Log.e("Record", "error: " + Integer.toString(length));
        else {
            for (WebSocket ws : wss)
                ws.sendBinary(buffer);
        }
        if (Thread.interrupted()) {
            recorder.stop();
            return;
        }
    }
}
 
开发者ID:zackszhu,项目名称:hack_sjtu_2017,代码行数:28,代码来源:LiuLiShuo.java

示例4: start

import android.media.AudioRecord; //导入方法依赖的package包/类
public void start(){
    if(!isStarted){
        stopFlag=false;

        mRecordBufferSize = AudioRecord.getMinBufferSize(mRecordSampleRate,
                mRecordChannelConfig, mRecordAudioFormat)*2;
        mRecord=new AudioRecord(MediaRecorder.AudioSource.MIC,mRecordSampleRate,mRecordChannelConfig,
                mRecordAudioFormat,mRecordBufferSize);
        mRecord.startRecording();
        try {
            MediaFormat format=convertAudioConfigToFormat(mConfig.mAudio);
            mAudioEncoder=MediaCodec.createEncoderByType(format.getString(MediaFormat.KEY_MIME));
            mAudioEncoder.configure(format,null,null,MediaCodec.CONFIGURE_FLAG_ENCODE);
            mAudioEncoder.start();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Thread thread=new Thread(new Runnable() {
            @Override
            public void run() {
                while (!stopFlag&&!audioEncodeStep(false)){};
                audioEncodeStep(true);
                Log.e("wuwang","audio stop");
                if(isStarted){
                    mRecord.stop();
                    mRecord.release();
                    mRecord=null;
                }
                if(mAudioEncoder!=null){
                    mAudioEncoder.stop();
                    mAudioEncoder.release();
                    mAudioEncoder=null;
                }
                isStarted=false;
            }
        });
        thread.start();
        startTime=SystemClock.elapsedRealtimeNanos();
        isStarted=true;
    }
}
 
开发者ID:aiyaapp,项目名称:AAVT,代码行数:42,代码来源:SoundRecorder.java

示例5: isCanUseAudio

import android.media.AudioRecord; //导入方法依赖的package包/类
/**
   * 判断是是否有录音权限
   */
  public static boolean isCanUseAudio(Activity activity) {
/*      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){//6.0以上系统
          if (ContextCompat.checkSelfPermission(activity,Manifest.permission.RECORD_AUDIO)!= PackageManager.PERMISSION_GRANTED) {
              return false;
          }else{
              return true;
          }

      }else {//6.0以下系统*/
      // 音频获取源
      int audioSource = MediaRecorder.AudioSource.MIC;
      // 设置音频采样率,44100是目前的标准,但是某些设备仍然支持22050,16000,11025
      int sampleRateInHz = 44100;
      // 设置音频的录制的声道CHANNEL_IN_STEREO为双声道,CHANNEL_CONFIGURATION_MONO为单声道
      int channelConfig = AudioFormat.CHANNEL_IN_STEREO;
      // 音频数据格式:PCM 16位每个样本。保证设备支持。PCM 8位每个样本。不一定能得到设备支持。
      int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
      // 缓冲区字节大小
      int bufferSizeInBytes;
      bufferSizeInBytes = AudioRecord.getMinBufferSize(sampleRateInHz,
              channelConfig, audioFormat);
      AudioRecord audioRecord = new AudioRecord(audioSource, sampleRateInHz,
              channelConfig, audioFormat, bufferSizeInBytes);
      //开始录制音频
      try {
          // 防止某些手机崩溃,例如联想
          audioRecord.startRecording();
      } catch (IllegalStateException e) {
          e.printStackTrace();
      }

      //根据开始录音判断是否有录音权限
      if (audioRecord.getRecordingState() != AudioRecord.RECORDSTATE_RECORDING) {
          // context.startActivity(new Intent(Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS));
          return false;
      } else {
          audioRecord.stop();
          audioRecord.release();
          return true;
      }

      // }


  }
 
开发者ID:zhonglikui,项目名称:cardinalsSample,代码行数:49,代码来源:DevicesUtil.java


注:本文中的android.media.AudioRecord.release方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。