0

我正在尝试使用 node-speaker 来朗读 Amazon polly 流,一旦读取,我就会将缓存保存到文件中,第二次我想用扬声器读取该文件。

它运行良好,但脚本正在退出Process finished with exit code 132 (interrupted by signal 4: SIGILL)

这是我的方法:

speak: (text, cacheDisabled = false) => {
    const hash = path.join(__dirname, 'cache', crypto.createHash('md5').update(text).digest('hex') + '.pcm')
    return new Promise((resolve, reject) => {
      fs.exists(hash, exist => {
        if (exist) {
          const audioFile = fs.createReadStream(hash)
          audioFile.pipe(this.player)

        }
        else {
          const audioFile = fs.createWriteStream(hash)

          const params = {
            'Text': text,
            'OutputFormat': 'pcm',
            'VoiceId': this.config.voiceId
          }
          this.polly.synthesizeSpeech(params, (err, data) => {
            if (err) {
              reject(err)
            }
            else if (data) {
              if (data.AudioStream instanceof Buffer) {
                // Initiate the source
                const bufferStream = new Stream.PassThrough()
                // convert AudioStream into a readable stream
                bufferStream.end(data.AudioStream)
                // save to file
                if (!cacheDisabled && !this.cacheDisabled) {
                  bufferStream.pipe(audioFile)
                }
                // Pipe into Player
                bufferStream.pipe(this.player)
                resolve()
              }
              else {
                reject()
              }
            }
          })
        }
      })
    })
  }

我的播放器是基本的:

this.player = new Speaker({
      channels: 1,
      bitDepth: 16,
      sampleRate: 16000
    })

知道如何防止这种情况吗?非常烦人,因为它使项目崩溃

4

1 回答 1

0

通过使用修复,npm install speaker --mpg123-backend=openal但这个模块似乎不再维护了:(

于 2017-08-26T07:09:37.010 回答