最近做翻译器项目,项目中用到科大语音翻译,语音动画需要自己写,对于我稍微有点复杂,把代码贴出来供大家参考下,不足之处请指正!
自定义控件包含有语音动画(音量大小波浪动画),音柱(音量大小音柱改变高低),文字(请讲话、识别中、翻译中)。
/**
* 自定义带音量大小动画的控件
*/
public class SoundView3 extends View {
//画笔
private Paint mPaint;
private Paint circlrPaint;
/**
* 声音音柱高度
*/
private float[] voiceLength = new float[]{
0.8f, 1.3f, 0.9f, 1.6f, 1, 2, 1};
/**
* 颜色值
*/
private int[] colorS = new int[]{
0xff2EBEB0, 0xff28B3DB, 0xff25A1F0, 0xff2695F0,
0xff25A1F0, 0xff26ADF0, 0xff2EBEB0};
private int rect_width = 6; //矩形的宽度
private int rect_distance; //矩形之间的间距
private float radius; //圆角
private float widthRect; //矩形占据总宽度7*8
private float distanceRect; //间隔间距的总尺寸6*12
private float drawWidth; //绘制的区域宽度尺寸 宽+间距,抖动部分总长度
private int soundNum = 1;
private int rect_height_defaule;
private int textSize = 18;