|
|
|
@@ -1,9 +1,21 @@ |
|
|
|
package com.aispeech.nativedemo.voiceprint; |
|
|
|
|
|
|
|
import android.graphics.Bitmap; |
|
|
|
import android.graphics.drawable.BitmapDrawable; |
|
|
|
import android.graphics.drawable.Drawable; |
|
|
|
import android.util.Log; |
|
|
|
|
|
|
|
import androidx.annotation.Nullable; |
|
|
|
|
|
|
|
import com.aispeech.nativedemo.utils.StatusUtils; |
|
|
|
import com.bumptech.glide.load.DataSource; |
|
|
|
import com.bumptech.glide.load.engine.DiskCacheStrategy; |
|
|
|
import com.bumptech.glide.load.engine.GlideException; |
|
|
|
import com.bumptech.glide.request.RequestListener; |
|
|
|
import com.bumptech.glide.request.target.Target; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
public class VoicePrintManager { |
|
|
|
@@ -61,8 +73,177 @@ public class VoicePrintManager { |
|
|
|
DeleteFeature.doDeleteFeature(requestUrl, APPID, apiSecret, apiKey, GroupId, "featureId"); |
|
|
|
/**8.删除声纹特征库*/ |
|
|
|
DeleteGroup.doDeleteGroup(requestUrl, APPID, apiSecret, apiKey, GroupId); |
|
|
|
|
|
|
|
// EpVideo epVideo = new EpVideo(orignalVideo.getAbsolutePath()); |
|
|
|
// |
|
|
|
// //水印位置大小 |
|
|
|
// Drawable drawable = context.getDrawable(waterResId); |
|
|
|
// BitmapDrawable bd = (BitmapDrawable) drawable; |
|
|
|
// Bitmap trb = bd.getBitmap(); |
|
|
|
// int waterWidth = getWaterPxWH(videoWidth, videoHeigt, trb.getWidth(), trb.getHeight())[0]; |
|
|
|
// int waterHeigt = getWaterPxWH(videoWidth, videoHeigt, trb.getWidth(), trb.getHeight())[1]; |
|
|
|
// int waterPx = videoWidth - waterWidth; |
|
|
|
// int waterPy = videoHeigt - waterHeigt; |
|
|
|
// |
|
|
|
// EpDraw draw = new EpDraw(waterCacheFile.getAbsolutePath(), waterPx, waterPy, waterWidth, waterHeigt, false, 0, videoDuration); |
|
|
|
// epVideo.addDraw(draw); |
|
|
|
// File output = new File(cacheDir, "video_water_" + orignalVideo.getName()); |
|
|
|
// |
|
|
|
// if (output.exists()){ |
|
|
|
// output.delete(); |
|
|
|
// } |
|
|
|
// |
|
|
|
// EpEditor.exec(epVideo, new EpEditor.OutputOption(output.getAbsolutePath()), new OnEditorListener() { |
|
|
|
// @Override |
|
|
|
// public void onSuccess() { |
|
|
|
// |
|
|
|
// if (addVideoWaterListener != null){ |
|
|
|
// addVideoWaterListener.genVideoWatered(new File(output.getAbsolutePath())); |
|
|
|
// } |
|
|
|
// |
|
|
|
// } |
|
|
|
// |
|
|
|
// @Override |
|
|
|
// public void onFailure() { |
|
|
|
// |
|
|
|
// if (addVideoWaterListener != null){ |
|
|
|
// addVideoWaterListener.genFaild(); |
|
|
|
// } |
|
|
|
// |
|
|
|
// } |
|
|
|
// |
|
|
|
// @Override |
|
|
|
// public void onProgress(final float v) { |
|
|
|
// |
|
|
|
// } |
|
|
|
// }); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// private void getVideoFrame(String pathInput, int quality) { |
|
|
|
// File file = FileUtils.getDiskCacheDir(mActivity, "select_frame_image.jpg"); |
|
|
|
// String thumbnailFile = file.getAbsolutePath(); |
|
|
|
// if (file.exists()) { |
|
|
|
// FileUtils.deleteFile(thumbnailFile); |
|
|
|
// } |
|
|
|
// String cmd = "-i "+pathInput+" -y -frames:v 1 -f image2 -q:v "+ quality+" " +thumbnailFile+ " "; |
|
|
|
// if (mIsGetFrameExecuting || mSelectBitmap == null) { |
|
|
|
// return; |
|
|
|
// } |
|
|
|
// mIsGetFrameExecuting = true; |
|
|
|
// try { |
|
|
|
// EpEditor.execCmd(cmd, 0, new OnEditorListener() { |
|
|
|
// @Override |
|
|
|
// public void onSuccess() { |
|
|
|
// mIsGetFrameExecuting = false; |
|
|
|
// mActivity.postInUIThread(new Runnable() { |
|
|
|
// @Override |
|
|
|
// public void run() { |
|
|
|
// mActivity.toast("cccc"); |
|
|
|
// mImageLoader.getManager() |
|
|
|
// .load(thumbnailFile) |
|
|
|
// .skipMemoryCache(true) |
|
|
|
// .diskCacheStrategy(DiskCacheStrategy.NONE) |
|
|
|
// .into(mBinding.pictureView); |
|
|
|
// } |
|
|
|
// }); |
|
|
|
// } |
|
|
|
// |
|
|
|
// @Override |
|
|
|
// public void onFailure() { |
|
|
|
// mIsGetFrameExecuting = false; |
|
|
|
// } |
|
|
|
// |
|
|
|
// @Override |
|
|
|
// public void onProgress(float progress) { |
|
|
|
// |
|
|
|
// } |
|
|
|
// }); |
|
|
|
// } catch (Exception e) { |
|
|
|
// Log.e("test", e.getMessage()); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// |
|
|
|
// private void getVideoFramesInit(String pathInput, long totalTime, int count, int quality) { |
|
|
|
// |
|
|
|
// if(count < 5)count = 5; |
|
|
|
// String size = "80x80"; |
|
|
|
// String pathOutput = "thumb_frame_image_out.jpg"; |
|
|
|
// File outFile = FileUtils.getDiskCacheDir(mActivity, pathOutput); |
|
|
|
// pathOutput = outFile.getAbsolutePath(); |
|
|
|
// if (pathOutput.lastIndexOf('.') > 0) { |
|
|
|
// pathOutput = pathOutput.substring(0, pathOutput.lastIndexOf('.')); |
|
|
|
// } |
|
|
|
// List<String> results = new ArrayList<>(); |
|
|
|
// for(int i=1; i<= count; i++){ |
|
|
|
// String tempIndex = String.valueOf(i); |
|
|
|
// String filename = pathOutput+tempIndex+ ".jpg"; |
|
|
|
// File file = new File(filename); |
|
|
|
// String thumbnailFile = file.getAbsolutePath(); |
|
|
|
// if (file.exists()) { |
|
|
|
// FileUtils.deleteFile(thumbnailFile); |
|
|
|
// } |
|
|
|
// Log.e("test", "file name " + thumbnailFile); |
|
|
|
// results.add(thumbnailFile); |
|
|
|
// } |
|
|
|
// pathOutput = pathOutput+"%8d"+ ".jpg"; |
|
|
|
// // callback(List.filled(count, "")); |
|
|
|
// |
|
|
|
// String cmd = "-i "+pathInput+" -y -f image2 -vf fps=fps=" +count + "/" + totalTime+" -s " + size + " "+ pathOutput; |
|
|
|
// EpEditor.execCmd(cmd, 0, new OnEditorListener() { |
|
|
|
// @Override |
|
|
|
// public void onSuccess() { |
|
|
|
// mActivity.postInUIThread(new Runnable() { |
|
|
|
// @Override |
|
|
|
// public void run() { |
|
|
|
// mActivity.toast("ffmpeg frames success"); |
|
|
|
// if (mVideoThumbFFmpegAdapter == null) { |
|
|
|
// mVideoThumbFFmpegAdapter = new VideoEnhanceTrimmerFFmpegAdapter(mActivity, ScreenUtil.dip2px(70.0f), mActivity.getImageLoader()); |
|
|
|
// mVideoThumbRecyclerView.setAdapter(mVideoThumbFFmpegAdapter); |
|
|
|
// } |
|
|
|
// mVideoThumbFFmpegAdapter.setData(results); |
|
|
|
// int index = results.size() /2; |
|
|
|
// String initPath = results.get(index); |
|
|
|
// setSelectFrameTime(50); |
|
|
|
// mImageLoader.getManager() |
|
|
|
// .asBitmap() |
|
|
|
// .addListener(new RequestListener<Bitmap>() { |
|
|
|
// @Override |
|
|
|
// public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) { |
|
|
|
// return false; |
|
|
|
// } |
|
|
|
// |
|
|
|
// @Override |
|
|
|
// public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) { |
|
|
|
// mSelectBitmap = resource; |
|
|
|
// return false; |
|
|
|
// } |
|
|
|
// }) |
|
|
|
// .load(initPath) |
|
|
|
// .diskCacheStrategy(DiskCacheStrategy.NONE) |
|
|
|
// .into(mBinding.pictureView); |
|
|
|
// } |
|
|
|
// }); |
|
|
|
// } |
|
|
|
// |
|
|
|
// @Override |
|
|
|
// public void onFailure() { |
|
|
|
// mActivity.postInUIThread(new Runnable() { |
|
|
|
// @Override |
|
|
|
// public void run() { |
|
|
|
// mActivity.toast("ffmpeg frames fail "); |
|
|
|
// } |
|
|
|
// }); |
|
|
|
// } |
|
|
|
// |
|
|
|
// @Override |
|
|
|
// public void onProgress(float progress) { |
|
|
|
// |
|
|
|
// } |
|
|
|
// }); |
|
|
|
// } |
|
|
|
|
|
|
|
public void createGroup() { |
|
|
|
/**1.创建声纹特征库*/ |
|
|
|
new Thread(new Runnable() { |
|
|
|
|