.intro.md•2.63 kB
voice
=================
[](https://fonoster.com)
[](https://npmjs.org/package/@fonoster/voice)
[](https://npmjs.org/package/@fonoster/voice)
[](https://github.com/fonoster/fonoster/blob/main/package.json)
The Voice module is a library for creating voice applications using the Fonoster API. It provides a simple way to create voice applications that can interact with the calling party using DTMF or speech recognition combined with simple verbs.
* [Installation](#installation)
* [Example](#example)
* [Voice Response](#VoiceResponse)
## Installation
```sh-session
$ npm install --save @fonoster/voice
```
## Example
A Voice Application is a server that controls a call's flow. A Voice Application can use any combination of the following verbs:
- `Answer` - Accepts an incoming call
- `Dial` - Passes the call to an Agent or a Number at the PSTN
- `Hangup` - Closes the call
- `Play` - Takes a URL or file and streams the sound back to the calling party
- `Say` - Takes a text, synthesizes the text into audio, and streams back the result
- `Gather` - Waits for DTMF or speech events and returns back the result
- `SGather` - Returns a stream for future DTMF and speech results
- `Stream` - Starts a stream to read and write audio into the call
- `Record` - It records the voice of the calling party and saves the audio on the Storage sub-system
- `Mute` - It tells the channel to stop sending media, effectively muting the channel
- `Unmute` - It tells the channel to allow media flow
Voice Application Example:
```typescript
const VoiceServer = require("@fonoster/voice").default;
const {
GatherSource,
VoiceRequest,
VoiceResponse
} = require("@fonoster/voice");
new VoiceServer().listen(async (req: VoiceRequest, voice: VoiceResponse) => {
const { ingressNumber, sessionRef, appRef } = req;
await voice.answer();
await voice.say("Hi there! What's your name?");
const { speech: name } = await res.gather({
source: GatherSource.SPEECH
});
await voice.say("Nice to meet you " + name + "!");
await voice.say("Please enter your 4 digit pin.");
const { digits } = await voice.gather({
maxDigits: 4,
finishOnKey: "#"
});
await voice.say("Your pin is " + digits);
await voice.hangup();
});
// Your app will live at tcp://127.0.0.1:50061
// and you can easily publish it to the Internet with:
// ngrok tcp 50061
```