首页 > 解决方案 > 使用文字转语音消息发起呼叫

问题描述

我为 NodeJs 使用 Asterisk-Manager 包

https://www.npmjs.com/package/asterisk-manager

并有一个磁带公告作为文本,必须通过文本翻译成语音。当我尝试拨打拨出电话号码时,如何设置文本到语音变量和收件人?一个例子是

ami.action({
    'action': 'originate',
    '??? phonenumber ???': '12345',
    '??? text to be spoken ???': 'Hello, this is a tape announcement'
  }, (err, res) => {
    if (err) {
        throw err;
    }

    console.log('everything was fine');
  });

编辑:

我知道 FreePbx 用于管理。据我所知,Asterisk 引擎有一个 TTS 模块。

我想我可以去这个代码

const { phoneNumber, announcement } = phoneInfo; // the required data

ami.action({
    channel: `SIP/${phoneNumber}`,
    application: 'SendText',
    data: announcement
}, (err, res) => {
    if (err) {
      throw err;
    }

    console.log(res);
});

引擎将管理数据属性

标签: javascriptnode.jsasteriskasteriskami

解决方案


Originate 应用程序本身只会将被叫号码发送到应用程序或分机。您应该在调用播放应用程序之前创建一个音频文件。因此,您的代码将如下所示:

let filePath = await yourTtsService.generateAudioFile('Hello, this is a tape announcement')

ami.action({
    'action': 'originate',
    'channel': 'SIP/123', // target number, depend on your trunk type
    'application': 'Playback',
    'data': filePath
})

要生成音频文件,您可以使用 google api,请参阅https://cloud.google.com/text-to-speech/docs/reference/libraries中的示例


推荐阅读