k2-fsa / sherpa-ncnn

Real-time speech recognition and voice activity detection (VAD) using next-gen Kaldi with ncnn without Internet connection. Support iOS, Android, Linux, macOS, Windows, Raspberry Pi, VisionFive2, LicheePi4A etc.
https://k2-fsa.github.io/sherpa/ncnn/index.html
Apache License 2.0
996 stars 154 forks source link

安卓端热词失效 #344

Closed 136323000 closed 3 months ago

136323000 commented 3 months ago

我这样设置热词内容:hotwords.txt文件中: 高 鼎

代码中配置:

val modelDir = "sherpa-ncnn-conv-emformer-transducer-2022-12-06"
        val hotwordsFilePath = "$modelDir/hotwords.txt"
        val hotwordsFile = getAssetFilePath(application.assets, hotwordsFilePath)

        Log.e("lc","hotwordsFilehotwordsFilehotwordsFile"+hotwordsFile)

        val config = RecognizerConfig(
            featConfig = featConfig,
            modelConfig = modelConfig,
            decoderConfig = decoderConfig,
            enableEndpoint = true,
            rule1MinTrailingSilence = 60*5f,
            rule2MinTrailingSilence = 60*5f,
            rule3MinUtteranceLength = 60*5f,
            hotwordsFile = hotwordsFile!!
        )

       private fun getAssetFilePath(assetManager: AssetManager, assetFilePath: String): String? {
              val inputStream: InputStream = assetManager.open(assetFilePath)
              val outFile = File(filesDir, assetFilePath)
              outFile.parentFile?.mkdirs()
              inputStream.use { input ->
                  FileOutputStream(outFile).use { output ->
                      input.copyTo(output)
                  }
              }
              return if (outFile.exists()) {
                  outFile.absolutePath
              } else {
                  null
              }
          }

我确信hotwordsFile 文件地址没有错 我可以用hotwordsFile 地址读取到文件内容 但是识别效果无法匹配到热词 我尝试下修改hotwordsScore的值 依然无效

附代码结构截图: image

对了 没有任何报错信息

csukuangfj commented 3 months ago

解码方法,用的是否modified_beam_search呢?

136323000 commented 3 months ago

解码方法,用的是否modified_beam_search呢?

感谢 修改了解码方式 热词生效了