如何在Android Studio中播放声音的同时录制语音?

时间:2016-04-14 08:23:55

标签: android-studio audio audio-recording

我正在开发名为" Parnk Call"当用户点击选择按钮的同时我还有想要从麦克风录制语音的人,已经保存录音的功能开始在calllayout上播放?

你能告诉我我们用来录制和播放的课程吗? 因为我无法弄清楚是MediaRecorder,AudioRecorder是否有助于录制? 对于播放声音音池或媒体播放器?

1 个答案:

答案 0 :(得分:0)

您应该阅读Android文档并分析在Android中录制和播放的多种方式中的哪种方式适合您的应用所需。在我的应用程序中,这对我有用:

播放:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

struct list_el
{
  float            val;
  struct list_el * next;
};

typedef struct list_el item;

int main()
{
  item *curr, *head;
  head = NULL;

  FILE * pointer = NULL;

  float  array[20];
  int    j;
  double xsq, ysq, B1, B0, R, rsq, rpart, rdevide, estimate;
  double estimate;
  double total_x   = 0;
  double total_y   = 0;
  double total_xsq = 0;
  double total_ysq = 0;
  double total_xy  = 4303108.0;
  double avg_x     = 0;
  double avg_y     = 0;

  pointer = fopen("dummy.txt", "r");

  //Store the data to a array from the pointer
  for(j = 0; j < 20; j++)
  {
    fscanf(pointer, "%f", &array[j]);
  }

  //make nodes and store data inside the each node head.. in this code segment i want to store two elements in one node
  for(j = 0; j < 20; j++)
  {
    curr       = (item *)malloc(sizeof(item));
    curr->val  = array[j];
    curr->next = head;
    head       = curr;
  }

  curr = head;

  for(j = 0; j < 20; j++)
  {
    if(j < 10)
    {
      printf("%.2f\n", curr->val);
      total_y   = total_y + curr->val;
      ysq       = curr->val;
      total_ysq = total_ysq + (ysq * ysq);
      curr      = curr->next;
    }
    else
    {
      printf("%.2f\n", curr->val);
      total_x   = total_x + curr->val;
      xsq       = curr->val;
      total_xsq = total_xsq + (xsq * xsq);
      curr      = curr->next;
    }
  }

  //calculate the average of data
  avg_x = total_x / 10.0;
  avg_y = total_y / 10.0;

  printf("Average \n");
  printf("X: %.3f\n", avg_x);
  printf("Y : %.3f\n\n", avg_y);

  fclose(pointer);
  return 0;

} //End of Main

录音:

AudioTrack fAudioTrack = new AudioTrack(STREAM_MUSIC, fs, CHANNEL_OUT_MONO,ENCODING_PCM_16BIT, 2*playbuffer.length, MODE_STATIC);

fAudioTrack.play();
//check the status through setPlaybackPositionUpdateListener

when finished (check inside onMarkerReached)
fAudioTrack.flush();
fAudioTrack.stop();
fAudioTrack.release();