detect the silence of audio

pull/190/head
xufuji456 4 years ago
parent ae08fa3cce
commit 272f8c853b
  1. 7
      app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.kt
  2. 16
      app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java
  3. 13
      app/src/main/res/layout/activity_audio_handle.xml
  4. 1
      app/src/main/res/values-en/strings.xml
  5. 1
      app/src/main/res/values/strings.xml
  6. 1
      gradlew

@ -105,7 +105,8 @@ class AudioHandleActivity : BaseActivity() {
R.id.btn_audio_speed,
R.id.btn_audio_echo,
R.id.btn_audio_tremolo,
R.id.btn_audio_denoise
R.id.btn_audio_denoise,
R.id.btn_audio_silence
)
}
@ -241,6 +242,10 @@ class AudioHandleActivity : BaseActivity() {
val noisePath = PATH + File.separator + "denoise.mp3"
commandLine = FFmpegUtil.audioDenoise(srcFile, noisePath)
}
R.id.btn_audio_silence
-> {
commandLine = FFmpegUtil.audioSilenceDetect(srcFile)
}
else -> {
}
}

@ -91,7 +91,6 @@ public class FFmpegUtil {
* @param inputPath input file
* @param delay delay to play
* @param outputPath output file
* @return mix success or not
*/
public static String[] audioEcho(String inputPath, int delay, String outputPath) {
// in_gain (0, 1], Default is 0.6
@ -110,7 +109,6 @@ public class FFmpegUtil {
* @param frequency frequency
* @param depth depth
* @param outputPath output file
* @return mix success or not
*/
public static String[] audioTremolo(String inputPath, int frequency, float depth, String outputPath) {
// frequency [0.1, 20000.0], Default is 5
@ -125,7 +123,6 @@ public class FFmpegUtil {
*
* @param inputPath input file
* @param outputPath output file
* @return mix success or not
*/
public static String[] audioDenoise(String inputPath, String outputPath) {
// nr: noise reduction in dB, [0.01 to 97], Default value is 12 dB
@ -136,6 +133,19 @@ public class FFmpegUtil {
return fftDenoiseCmd.split(" ");
}
/**
* Detect silence of a chunk of audio
*
* @param inputPath input file
*/
public static String[] audioSilenceDetect(String inputPath) {
// silence_start: 268.978
// silence_end: 271.048 | silence_duration: 2.06975
String silenceCmd = "ffmpeg -i %s -af silencedetect=noise=0.0001 -f null -";
silenceCmd = String.format(Locale.getDefault(), silenceCmd, inputPath);
return silenceCmd.split(" ");
}
/**
* mux audio and video together
*

@ -44,14 +44,16 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/audio_play"
android:layout_marginTop="10dp" />
android:layout_marginTop="10dp"
android:visibility="gone"/>
<Button
android:id="@+id/btn_play_opensl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/audio_opensl"
android:layout_marginTop="10dp" />
android:layout_marginTop="10dp"
android:visibility="gone"/>
<Button
android:id="@+id/btn_audio_encode"
@ -97,6 +99,13 @@
android:text="@string/audio_denoise"
android:layout_marginTop="10dp" />
<Button
android:id="@+id/btn_audio_silence"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/audio_silence"
android:layout_marginTop="10dp" />
</LinearLayout>
<include

@ -12,6 +12,7 @@
<string name="audio_echo">Echo effect</string>
<string name="audio_tremolo">Tremolo effect</string>
<string name="audio_denoise">Audio denoise</string>
<string name="audio_silence">Silence detect</string>
<string name="audio_effect">Audio effect</string>
<string name="audio_equalizer">Audio equalizer:</string>
<string name="audio_style">Audio style:</string>

@ -12,6 +12,7 @@
<string name="audio_echo">空灵效果</string>
<string name="audio_tremolo">惊悚效果</string>
<string name="audio_denoise">音频降噪</string>
<string name="audio_silence">静音检测</string>
<string name="audio_effect">音乐均衡器</string>
<string name="audio_equalizer">均衡器:</string>
<string name="audio_style">风格:</string>

1
gradlew vendored

@ -158,3 +158,4 @@ eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"

Loading…
Cancel
Save