Improving read me and encoding support
This commit is contained in:
@@ -9,7 +9,7 @@ This project is a FastAPI-based chatbot that integrates with Telnyx to handle We
|
||||
- [Features](#features)
|
||||
- [Requirements](#requirements)
|
||||
- [Installation](#installation)
|
||||
- [Configure Telnyx URLs](#configure-telnyx-urls)
|
||||
- [Configure Telnyx TeXML application](#configure-telnyx-texml-application)
|
||||
- [Running the Application](#running-the-application)
|
||||
- [Using Python (Option 1)](#using-python-option-1)
|
||||
- [Using Docker (Option 2)](#using-docker-option-2)
|
||||
@@ -54,7 +54,7 @@ This project is a FastAPI-based chatbot that integrates with Telnyx to handle We
|
||||
4. **Install ngrok**:
|
||||
Follow the instructions on the [ngrok website](https://ngrok.com/download) to download and install ngrok.
|
||||
|
||||
## Configure Telnyx URLs
|
||||
## Configure Telnyx TeXML application
|
||||
|
||||
1. **Start ngrok**:
|
||||
In a new terminal, start ngrok to tunnel the local server:
|
||||
@@ -76,6 +76,8 @@ This project is a FastAPI-based chatbot that integrates with Telnyx to handle We
|
||||
```
|
||||
- In `templates/streams.xml`, replace `<your server url>` with your ngrok URL (without `https://`)
|
||||
- The final URL should look like: `wss://abc123.ngrok.io/ws`
|
||||
- The encoding (`bidirectionalCodec`) should be `PCMU` or `PCMA` depending on your needs. Based on selected encoding, set the outbound_encoding in the `TelnyxFrameSerializer` in `src/pipecat/serializers/telnyx.py`
|
||||
- The inbound encoding can be controlled from the application configuration for inbound calls and dial/transfer commands for outbound calls.
|
||||
|
||||
## Running the Application
|
||||
|
||||
|
||||
@@ -25,11 +25,12 @@ class TelnyxFrameSerializer(FrameSerializer):
|
||||
class InputParams(BaseModel):
|
||||
telnyx_sample_rate: int = 8000
|
||||
sample_rate: int = 16000
|
||||
encoding: str = "PCMU"
|
||||
inbound_encoding: str = "PCMU"
|
||||
outbound_encoding: str = "PCMU"
|
||||
|
||||
def __init__(self, stream_id: str, encoding: str, params: InputParams = InputParams()):
|
||||
self._stream_id = stream_id
|
||||
params.encoding = encoding
|
||||
params.inbound_encoding = encoding
|
||||
self._params = params
|
||||
|
||||
@property
|
||||
@@ -40,9 +41,9 @@ class TelnyxFrameSerializer(FrameSerializer):
|
||||
if isinstance(frame, AudioRawFrame):
|
||||
data = frame.audio
|
||||
|
||||
if self._params.encoding == "PCMU":
|
||||
if self._params.outbound_encoding == "PCMU":
|
||||
serialized_data = pcm_to_ulaw(data, frame.sample_rate, self._params.telnyx_sample_rate)
|
||||
elif self._params.encoding == "PCMA":
|
||||
elif self._params.outbound_encoding == "PCMA":
|
||||
serialized_data = pcm_to_alaw(data, frame.sample_rate, self._params.telnyx_sample_rate)
|
||||
else:
|
||||
raise ValueError(f"Unsupported encoding: {self._params.encoding}")
|
||||
@@ -62,18 +63,15 @@ class TelnyxFrameSerializer(FrameSerializer):
|
||||
def deserialize(self, data: str | bytes) -> Frame | None:
|
||||
message = json.loads(data)
|
||||
|
||||
if message["event"] == "start":
|
||||
print(f"Start received encoding:{message['start']['media_format']['encoding']}")
|
||||
self._params.encoding = message["start"]["media_format"]["encoding"]
|
||||
if message["event"] == "media":
|
||||
payload_base64 = message["media"]["payload"]
|
||||
payload = base64.b64decode(payload_base64)
|
||||
|
||||
if self._params.encoding == "PCMU":
|
||||
if self._params.inbound_encoding == "PCMU":
|
||||
deserialized_data = ulaw_to_pcm(
|
||||
payload, self._params.telnyx_sample_rate, self._params.sample_rate
|
||||
)
|
||||
elif self._params.encoding == "PCMA":
|
||||
elif self._params.inbound_encoding == "PCMA":
|
||||
deserialized_data = alaw_to_pcm(
|
||||
payload, self._params.telnyx_sample_rate, self._params.sample_rate
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user