# Stream the audio to STT

**URL:** <https://community.asterisk.org/t/stream-the-audio-to-stt/99132>\
**Category:** Asterisk APIs\
**Created:** [October 17, 2023, 10:00am UTC](https://community.asterisk.org/t/stream-the-audio-to-stt/99132 "2023-10-17T10:00:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsonchan000](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/jsonchan000/32/6979_2.png) [@jsonchan000](https://community.asterisk.org/u/jsonchan000)\
**Post date:** [October 17, 2023, 10:00am UTC](https://community.asterisk.org/t/stream-the-audio-to-stt/99132/1 "2023-10-17T10:00:54Z")

</div>

Hi I am looking for a stream audio solution. I tried Asterisk External Media

index.js

```auto
  //Start the server that receives audio from Asterisk.
  console.log('Starting audio listener');
  let audioServer = new rtp.RtpUdpServerSocket(process.env.listenServer, false, process.env.audioOutput || false);

```

result

```auto
Starting audio listener
server error:
Error: getaddrinfo ENOTFOUND http
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:108:26)
server socket closed

```

.env

```auto
listenServer = "http://Asterisk-publicIP:5000"

```

How can I fix the bug? Thanks

---

<div class="post-metadata">

**Author:** ![Chano](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/chano/32/3448_2.png) [@Chano](https://community.asterisk.org/u/Chano)\
**Post date:** [October 17, 2023, 10:40am UTC](https://community.asterisk.org/t/stream-the-audio-to-stt/99132/2 "2023-10-17T10:40:51Z")

</div>

Seems to be a DNS or other name resolution problem. Not related to Asterisk.

---

<div class="post-metadata">

**Author:** ![jcolp](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/jcolp/32/8848_2.png) [@jcolp](https://community.asterisk.org/u/jcolp)\
**Post date:** [October 17, 2023, 11:05am UTC](https://community.asterisk.org/t/stream-the-audio-to-stt/99132/3 "2023-10-17T11:05:34Z")

</div>

It’s not an HTTP address. It’s the local host/IP and port for the example to listen on:

```auto
listenServer = "Asterisk-publicIP:5000"

```

---

<div class="post-metadata">

**Author:** ![jsonchan000](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/jsonchan000/32/6979_2.png) [@jsonchan000](https://community.asterisk.org/u/jsonchan000)\
**Post date:** [October 26, 2023, 10:49am UTC](https://community.asterisk.org/t/stream-the-audio-to-stt/99132/4 "2023-10-26T10:49:20Z")

</div>

Thanks for your quick help, I can connect listenServer but I still cannot stream audio.  
I am following the “Asterisk External Media Sample” to stream the audio from asterisk. Here is my goal:

run index.js → Create ARI Controller → Cretae a bridge and a local channel → call a number (local/1234) → stream the channel audio to “output path”

All the conenction work well and it called local/1234, however no audio stream to the output path. I didnot got any warning and error.

Am i missing something?

**index.js**

```auto
'use strict';

// import 
const client = require('ari-client');

const ari = require('.//AriController');
const wss = require('.//websocketServer');
const mq = require('.//mqttClient');
const rtp = require('.//RtpUdpServerSocket');

let channels = new Map();

console.log('Starting');

async function main() {
  // Create the ARI Controller instance but don't start it yet.
  console.log(`Creating ARI Controller to Asterisk instance ${process.env.ariServerUrl}, but not yet start`);
  let ariController = new ari.AriController();
  ariController.on('close', () => {
    audioServer.close();
    process.exit(0);
  });

  ariController.connectARI();

  //Start the server that receives audio from Asterisk.
  console.log('Starting audio listener');
  let audioServer = new rtp.RtpUdpServerSocket(process.env.listenServer, process.env.audioOutput);
}

main();

```

**AriController.js**

```auto
const EventEmitter = require('events');
const ari = require('ari-client');

class AriController extends EventEmitter {
    constructor() {
        super();
    }

    async close() {
        if (this.closing) {
            return;
        }
        this.closing = true;

        if (this.localChannel) {
            console.log("Hanging up local channel");
            try {
                await this.localChannel.hangup();
            } catch (error) {
            }
            delete this.localChannel;
        }
        if (this.externalChannel) {
            console.log("Hanging up external media channel");
            try {
                await this.externalChannel.hangup();
            } catch (error) {
            }
            delete this.externalChannel;
        }
        if (this.bridge) {
            console.log("Destroying bridge");
            try {
                await this.bridge.destroy();
            } catch (error) {
            }
            delete this.bridge;
        }

        await this.ari.stop();
        this.emit('close');
    }

    //this function start the ARI (connect to PBX)
    async connectARI() {
        this.ari = await ari.connect(process.env.ariServerUrl, process.env.ariUser, process.env.ariPassword);

        await this.ari.start("externalMedia");

        // Create a simple bridge that is controlled by ARI/Stasis
        this.bridge = this.ari.Bridge();
        try {
            await this.bridge.create({ type: "mixing" });
        } catch (error) {
            console.error(error);
            this.close();
        }
        this.bridge.on('BridgeDestroyed', (event) => {
            console.log('BridgeDestroyed');
            this.close();
        });

        /*
         * Create the local channel. This actually creates 2
         * back to back channels, one that's controlled by ARI/Stasis
         * that we can put into the bridge we created above and 
         * another one the one that dials a phone, confbridge, etc.
         * and joins _that_ bridge. 
         *  
         * localChannel below is actually the first channel. 
         */
        this.localChannel = this.ari.Channel();
        this.localChannel.on('StasisStart', (event, chan) => {
            this.bridge.addChannel({ channel: chan.id });
        });
        this.localChannel.on('StasisEnd', (event, chan) => {
            console.log('StasisEnd');
            this.close();
        });

        // Call the phone or confbridge specified in dialstring
        try {
            await this.localChannel.originate({
                endpoint: process.env.dialstring, formats: process.env.format, app: "externalMedia",
            });
        } catch (error) {
            console.error(error);
            this.close();
        }

        // Now we create the External Media channel.
        this.externalChannel = this.ari.Channel();
        this.externalChannel.on('StasisStart', (event, chan) => {
            this.bridge.addChannel({ channel: chan.id });
        });
        this.externalChannel.on('StasisEnd', (event, chan) => {
            console.log('StasisEnd');
            this.close();
        });

        /*
         * We give the external channel the address of the listener
         * we already set up and the format it should stream in.
         */
        try {
            let resp = await this.externalChannel.externalMedia({
                app: "externalMedia",
                external_host: process.env.listenServer,
                format: process.env.format
            });
            this.emit('ready');
        } catch (error) {
            console.error(error);
            this.close();
        }
    }
}

module.exports.AriController = AriController;

```

**output**

 ![image](https://global.discourse-cdn.com/asterisk/original/2X/9/9e132169f9ebd3b97b0dca1e531b3ee127d00512.jpeg)

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/asterisk/original/2X/4/475d0c889911cfb84ac4881ad6df8b523e3f9105.png) [@system](https://community.asterisk.org/u/system)\
**Post date:** [November 25, 2023, 10:50am UTC](https://community.asterisk.org/t/stream-the-audio-to-stt/99132/5 "2023-11-25T10:50:04Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
