You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[docs sprint] python quickstart + working with phone calls (#27)
* deprecate SpeakerOutput
* remove play.ht default voice id
* rename open source quickstarts page
* remove building block reference
* update python quickstart
* extra steps to deprecate speakeroutput
* finish telephony docs
* fix some references + language in how-to-use-it
* fix test
Copy file name to clipboardexpand all lines: docs/open-source/python-quickstart.mdx
+54-37
Original file line number
Diff line number
Diff line change
@@ -8,14 +8,11 @@ description: "Get up and running using Python"
8
8
Install the [vocode package](https://pypi.org/project/vocode/):
9
9
10
10
```bash
11
-
pip install 'vocode[io]'
11
+
pip install vocode
12
12
```
13
13
14
14
# Getting started
15
15
16
-
The `io` extra installs the packages necessary to run our voice conversations locally, but is not needed for other surfaces, e.g. [phone calls](/open-source/telephony).
17
-
You may need to install [portaudio](https://formulae.brew.sh/formula/portaudio) and [ffmpeg](https://formulae.brew.sh/formula/ffmpeg) on your system.
18
-
19
16
## Working with system audio
20
17
21
18
We provide helper methods to hook into your system audio.
@@ -33,74 +30,94 @@ If the default I/O devices are not being set properly, set `use_default_devices`
33
30
Vocode provides a unified interface across various speech transcription, speech synthesis, and AI/NLU providers.
34
31
To use these providers with Vocode, you'll need to grab credentials from these providers and set them in the Vocode environment.
35
32
36
-
```python
37
-
# these can also be set as environment variables
38
-
vocode.setenv(
39
-
OPENAI_API_KEY="<your OpenAI key>",
40
-
DEEPGRAM_API_KEY="<your Deepgram key>",
41
-
AZURE_SPEECH_KEY="<your Azure key>",
42
-
AZURE_SPEECH_REGION="<your Azure region>",
43
-
)
44
-
```
33
+
You can either set the following parameters as environment variables (e.g. by specifying them in a `.env` file and using a package like `python-dotenv` to load), or set them manually in the pydantic settings (see below).
45
34
46
35
For AZURE_SPEECH_REGION you should use the URL format. For example, if you're using the "East US" region, the value should be "eastus". See [Azure Region list](https://learn.microsoft.com/en-us/azure/cognitive-services/speech-service/rest-text-to-speech?tabs=streaming#prebuilt-neural-voices).
47
36
48
37
## `StreamingConversation` example
49
38
39
+
This can also be found in the [`quickstarts` directory](https://github.com/vocodedev/vocode-core/blob/main/quickstarts/streaming_conversation.py) of the repo.
40
+
50
41
```python
51
42
import asyncio
52
43
import signal
53
44
54
-
importvocode
55
-
from vocode.streaming.streaming_conversation import StreamingConversation
45
+
from pydantic_settings importBaseSettings, SettingsConfigDict
46
+
56
47
from vocode.helpers import create_streaming_microphone_input_and_speaker_output
57
-
from vocode.streaming.models.transcriber import (
58
-
DeepgramTranscriberConfig,
59
-
PunctuationEndpointingConfig,
60
-
)
48
+
from vocode.logging import configure_pretty_logging
61
49
from vocode.streaming.agent.chat_gpt_agent import ChatGPTAgent
62
50
from vocode.streaming.models.agent import ChatGPTAgentConfig
63
51
from vocode.streaming.models.message import BaseMessage
64
52
from vocode.streaming.models.synthesizer import AzureSynthesizerConfig
53
+
from vocode.streaming.models.transcriber import (
54
+
DeepgramTranscriberConfig,
55
+
PunctuationEndpointingConfig,
56
+
)
57
+
from vocode.streaming.streaming_conversation import StreamingConversation
65
58
from vocode.streaming.synthesizer.azure_synthesizer import AzureSynthesizer
66
59
from vocode.streaming.transcriber.deepgram_transcriber import DeepgramTranscriber
67
60
68
-
# these can also be set as environment variables
69
-
vocode.setenv(
70
-
OPENAI_API_KEY="<your OpenAI key>",
71
-
DEEPGRAM_API_KEY="<your Deepgram key>",
72
-
AZURE_SPEECH_KEY="<your Azure key>",
73
-
AZURE_SPEECH_REGION="<your Azure region>",
74
-
)
61
+
configure_pretty_logging()
62
+
63
+
64
+
classSettings(BaseSettings):
65
+
"""
66
+
Settings for the streaming conversation quickstart.
67
+
These parameters can be configured with environment variables.
Copy file name to clipboardexpand all lines: docs/open-source/telephony.mdx
+22-11
Original file line number
Diff line number
Diff line change
@@ -117,8 +117,6 @@ Make sure the server we just set up is already running. Then, in `outbound_call.
117
117
118
118
Replace the `to_phone` with the number you want to call and the `from_phone` with the number you want to call from. In order to make a call from the `from_phone`, you must have access to it via Twilio (either a number purchased via Twilio or verify the caller ID).
119
119
120
-
> Note: To ensure legal compliance with robocall regulations in California, the following code snippet from the [Vocode library](https://github.com/vocodedev/vocode-python/blob/main/vocode/streaming/telephony/conversation/outbound_call.py#L83-L96) utilizes Twilio Line Intelligence to check if calls are made to mobile phones: For Canadian phone numbers, the Twilio Lookup API may not return carrier data due to the Canadian Local Number Portability Consortium (CLNPC) requirements. More information on this issue can be found in the [Twilio Support Article](https://support.twilio.com/hc/en-us/articles/360004563433-Twilio-Lookup-API-is-Not-Returning-Carrier-Data-for-Canadian-Phone-Numbers).
121
-
122
120
Run the script with `poetry run python outbound_call.py`.
123
121
124
122
## Configuration
@@ -129,26 +127,39 @@ or `SynthesizerConfig` - the default transcriber is Deepgram and the default syn
129
127
This example sets up an agent that spells every word that is sent to it - any text-in, text-out function can be turned into a voice conversation by subclassing `BaseAgent` and creating an `AgentFactory`.
130
128
131
129
```
130
+
import typing
131
+
from typing import Optional, Tuple
132
+
133
+
from vocode.streaming.agent.abstract_factory import AbstractAgentFactory
134
+
from vocode.streaming.agent.base_agent import BaseAgent, RespondAgent
135
+
from vocode.streaming.agent.chat_gpt_agent import ChatGPTAgent
136
+
from vocode.streaming.models.agent import AgentConfig, AgentType, ChatGPTAgentConfig
137
+
138
+
132
139
class SpellerAgentConfig(AgentConfig, type="agent_speller"):
# If the agent configuration type is not recognized, raise an exception.
162
+
raise Exception("Invalid agent config")
152
163
```
153
164
154
165
An `AgentFactory` instance is passed into the `TelephonyServer` in `telephony_app.py`.
@@ -157,7 +168,7 @@ We provide a small set of agents with already created `AgentConfig`s, including,
157
168
158
169
### Accessing call information in your agent
159
170
160
-
We store the `to` and `from` numbers in the [`ConfigManager`](https://github.com/vocodedev/vocode-python-sdk/blob/b37bf7a1172a917b641d0e70ba14756415e09b0b/apps/telephony_app/main.py#L20) - so
171
+
We store the `to` and `from` numbers in the [`ConfigManager`](https://github.com/vocodedev/vocode-core/blob/53b01dab0b59f71961ee83dbcaf3653a6935c2e3/apps/telephony_app/main.py#L30) - so
161
172
if you'd like to access them in your agent, you can instantiate the manager to hook into the same Redis instance:
162
173
163
174
```
@@ -168,7 +179,7 @@ class SpellerAgent(BaseAgent):
0 commit comments