Skip to content
프로젝트

소개

사용자의 음성에 반응해 물결 효과를 표시하는 음성 녹음 버튼입니다.

웹 및 앱 개발

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

VoiceRipple

API Download

About

Voice Record Button that has ripple effect with users voice. Calculation of decibels from max amplitude by using the following:

power_db = 20 * log10(amp / amp_ref)

Main method consists the following:

if (THRESHOLD >= 0) {
  if (rippleRadius - THRESHOLD >= powerDb + MIN_RADIUS || powerDb + MIN_RADIUS >= rippleRadius + THRESHOLD) {
    rippleRadius = powerDb + MIN_RADIUS;
    backgroundRadius = (int) (rippleRadius * backgroundRippleRatio);
  } else {
    // if decreasing velocity reached 0, it should simply match with ripple radius
    if (((backgroundRadius - rippleRadius) / rippleDecayRate) == 0) {
      backgroundRadius = rippleRadius;
    } else {
      backgroundRadius = backgroundRadius - ((backgroundRadius - rippleRadius) / rippleDecayRate);
    }
  }

  invalidate();
}

The approximated decibel power of the sound is used to animate the button's ripple effect.

Demo

Implement

repositories {
  jcenter()
}

dependencies {
  compile "info.kimjihyok:voice-ripple-record-button:${voice-ripple-button-version}"
}

XML Setup

<info.kimjihyok.ripplelibrary.VoiceRippleView
    android:id="@+id/voice_ripple_view"
    android:layout_width="200dp"
    android:layout_height="200dp"
    app:rippleColor="@color/colorPrimary"/>

Setter for view and android recorder related setup

voiceRipple = (VoiceRippleView) findViewById(R.id.voice_ripple_view);

// set view related settings for ripple view
voiceRipple.setRippleColor(ContextCompat.getColor(this, R.color.colorPrimary));
voiceRipple.setRippleSampleRate(Rate.LOW);
voiceRipple.setRippleDecayRate(Rate.HIGH);
voiceRipple.setBackgroundRippleRatio(1.4);

// set recorder related settings for ripple view
voiceRipple.setMediaRecorder(new MediaRecorder());
voiceRipple.setOutputFile(audioFile.getAbsolutePath());
voiceRipple.setAudioSource(MediaRecorder.AudioSource.MIC);
voiceRipple.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
voiceRipple.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

Setter for recording status related setup

// set inner icon for record and recording
voiceRipple.setRecordDrawable(ContextCompat.getDrawable(this, R.drawable.record), ContextCompat.getDrawable(this, R.drawable.recording));
voiceRipple.setIconSize(30);

// change recording status when clicked
voiceRipple.setOnClickListener(new View.OnClickListener() {
  @Override
  public void onClick(View view) {
   if (voiceRipple.isRecording()) {
      voiceRipple.stopRecording();
    } else {
      try {
        voiceRipple.startRecording();
      } catch (IOException e) {
        Log.e(TAG, "startRecording() error: ", e);
      }
    }
  }
});

Stop and Destory

// It is required to stop VoiceRippleView at onStop and to destory at onDestory to prevent memory leak and unexpected
@Override
protected void onStop() {
  super.onStop();
  voiceRipple.onStop();
}
 
@Override
protected void onDestroy() {
  super.onDestroy();
  voiceRipple.onDestroy();
}

관련 프로젝트 살펴보기

불러오는 중…