语音增强TFLite模型的安卓部署

本文详细记录了如何在安卓平台上使用Java部署语音增强的TFLite模型,模型主要由频域和时域的LSTM组成,用于实现语音降噪。文章介绍了模型加载和infer函数的调用方法,并提供了相关参考资料。
摘要由CSDN通过智能技术生成

语音增强TFLite模型的安卓java部署

TF官网对于关于图像的深度学习模型部署提供了较多的demo,但是对于语音特别是语音增强的示例较少。本文对使用java在安卓部署语音增强模型进行详细记录。

语音增强模型(降噪)使用的是DTLN模型,DTLN是两个模型串联在一起的模型,一个频域的LSTM,一个时域的LSTM。

1. 官网关于模型加载的函数

private MappedByteBuffer loadModelFile(String model) throws IOException {
        AssetFileDescriptor fileDescriptor = getApplicationContext().getAssets().openFd(model + ".tflite");
        FileInputStream inputStream = new FileInputStream(fileDescriptor.getFileDescriptor());
        FileChannel fileChannel = inputStream.getChannel();
        long startOffset = fileDescriptor.getStartOffset();
        long declaredLength = fileDescriptor.getDeclaredLength();
        return fileChannel.map(FileChannel.MapMode.READ_ONLY, startOffset, declaredLength);
    }

2. 调用模型infer函数

private void loadModule1() {
        String model1 = "model_1";
        try {
            Interpreter.Options options = new Interpreter.Options();
            options.setNumThreads(4);
            options.setUseNNAPI(true);
            // 加载模型文件
            tflite1 = new Interpreter(loadModelFile(model1), options);
            Toast.makeText(MainActivity.this, model1 + " model load success", Toast.LENGTH_SHORT).show();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

3.模型infer函数

    public float[][][] model1_infer(double [] spec){

            float [] spec_f = new float[spec.length];
            
            for (int i=0; i<spec.length; i++){
                spec_f[i] = (float) spec[i];
            }

            float[][][] input1 =new float[1][1][257];
            //input1赋初值
            //System.out.println(input1[0][0][i]);
            System.arraycopy(spec_f, 0, input1[0][0], 0, 257);
//            for (int i = 0; i < 257; i++) {
//                System.out.println(input1[0][0][i]);
//            }
            float[][][] output1 = new float[1][1][257];
            //System.out.println(output1[0][0][0]); //自动给定初值0.0
            float[][][]
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值