├── .devcontainer ├── Dockerfile └── devcontainer.json ├── .env.example ├── .github ├── BRANCH_AND_RELEASE_PROCESS.md ├── CODE_CONTRIBUTIONS_GUIDE.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── GITHUB_WORKFLOW.md ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── config.yml │ └── feature_request.md ├── PULL_REQUEST_TEMPLATE.md ├── images │ └── git_workflow.png └── workflows │ ├── CD-dev.yml │ ├── CD.yaml │ ├── CI.yaml │ ├── PyDocs.yaml │ ├── check-actionlint.yaml │ ├── check-all.yaml │ ├── check-lint.yaml │ ├── check-mdlint.yaml │ ├── check-shell.yaml │ ├── check-static.yaml │ ├── check-yaml.yaml │ ├── tests-daily.yaml │ └── tests-unit.yaml ├── .gitignore ├── .markdownlintrc ├── .pylintrc ├── .yamllintconfig.yaml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── Makefile ├── README.md ├── deepgram ├── __init__.py ├── audio │ ├── __init__.py │ ├── microphone │ │ ├── __init__.py │ │ ├── constants.py │ │ ├── errors.py │ │ └── microphone.py │ └── speaker │ │ ├── __init__.py │ │ ├── constants.py │ │ ├── errors.py │ │ └── speaker.py ├── client.py ├── clients │ ├── __init__.py │ ├── agent │ │ ├── __init__.py │ │ ├── client.py │ │ ├── enums.py │ │ └── v1 │ │ │ ├── __init__.py │ │ │ └── websocket │ │ │ ├── __init__.py │ │ │ ├── async_client.py │ │ │ ├── client.py │ │ │ ├── options.py │ │ │ └── response.py │ ├── agent_router.py │ ├── analyze │ │ ├── __init__.py │ │ ├── client.py │ │ └── v1 │ │ │ ├── __init__.py │ │ │ ├── async_client.py │ │ │ ├── client.py │ │ │ ├── helpers.py │ │ │ ├── options.py │ │ │ └── response.py │ ├── auth │ │ ├── __init__.py │ │ ├── client.py │ │ └── v1 │ │ │ ├── __init__.py │ │ │ ├── async_client.py │ │ │ ├── client.py │ │ │ └── response.py │ ├── common │ │ ├── __init__.py │ │ └── v1 │ │ │ ├── __init__.py │ │ │ ├── abstract_async_rest.py │ │ │ ├── abstract_async_websocket.py │ │ │ ├── abstract_sync_rest.py │ │ │ ├── abstract_sync_websocket.py │ │ │ ├── enums.py │ │ │ ├── errors.py │ │ │ ├── helpers.py │ │ │ ├── options.py │ │ │ ├── rest_response.py │ │ │ ├── shared_response.py │ │ │ ├── websocket_events.py │ │ │ └── websocket_response.py │ ├── errors.py │ ├── listen │ │ ├── __init__.py │ │ ├── client.py │ │ ├── enums.py │ │ └── v1 │ │ │ ├── __init__.py │ │ │ ├── rest │ │ │ ├── __init__.py │ │ │ ├── async_client.py │ │ │ ├── client.py │ │ │ ├── helpers.py │ │ │ ├── options.py │ │ │ └── response.py │ │ │ └── websocket │ │ │ ├── __init__.py │ │ │ ├── async_client.py │ │ │ ├── client.py │ │ │ ├── options.py │ │ │ └── response.py │ ├── listen_router.py │ ├── live │ │ ├── __init__.py │ │ └── v1 │ │ │ ├── __init__.py │ │ │ ├── client.py │ │ │ └── enums.py │ ├── manage │ │ ├── __init__.py │ │ ├── client.py │ │ └── v1 │ │ │ ├── __init__.py │ │ │ ├── async_client.py │ │ │ ├── client.py │ │ │ ├── options.py │ │ │ └── response.py │ ├── prerecorded │ │ ├── __init__.py │ │ └── v1 │ │ │ ├── __init__.py │ │ │ ├── client.py │ │ │ └── errors.py │ ├── read_router.py │ ├── selfhosted │ │ ├── __init__.py │ │ ├── client.py │ │ └── v1 │ │ │ ├── __init__.py │ │ │ ├── async_client.py │ │ │ └── client.py │ ├── speak │ │ ├── __init__.py │ │ ├── client.py │ │ ├── enums.py │ │ └── v1 │ │ │ ├── __init__.py │ │ │ ├── rest │ │ │ ├── __init__.py │ │ │ ├── async_client.py │ │ │ ├── client.py │ │ │ ├── helpers.py │ │ │ ├── options.py │ │ │ └── response.py │ │ │ └── websocket │ │ │ ├── __init__.py │ │ │ ├── async_client.py │ │ │ ├── client.py │ │ │ ├── options.py │ │ │ └── response.py │ └── speak_router.py ├── errors.py ├── options.py └── utils │ ├── __init__.py │ └── verboselogs │ └── __init__.py ├── examples ├── README.md ├── advanced │ ├── README.md │ ├── rest │ │ └── direct_invocation │ │ │ └── main.py │ └── websocket │ │ ├── direct_invocation │ │ └── main.py │ │ ├── microphone_inheritance │ │ ├── README.md │ │ └── main.py │ │ └── mute-microphone │ │ └── main.py ├── agent │ ├── async_simple │ │ └── main.py │ ├── no_mic │ │ └── main.py │ └── simple │ │ └── main.py ├── analyze │ ├── intent │ │ ├── conversation.txt │ │ └── main.py │ ├── legacy_dict_intent │ │ ├── conversation.txt │ │ └── main.py │ ├── sentiment │ │ ├── conversation.txt │ │ └── main.py │ ├── stream_intent │ │ ├── conversation.txt │ │ └── main.py │ ├── summary │ │ ├── conversation.txt │ │ └── main.py │ └── topic │ │ ├── conversation.txt │ │ └── main.py ├── auth │ ├── async_token │ │ └── main.py │ └── token │ │ └── main.py ├── manage │ ├── async_invitations │ │ └── main.py │ ├── async_models │ │ └── main.py │ ├── balances │ │ └── main.py │ ├── invitations │ │ └── main.py │ ├── keys │ │ └── main.py │ ├── legacy_dict_invitations │ │ └── main.py │ ├── members │ │ └── main.py │ ├── models │ │ └── main.py │ ├── projects │ │ └── main.py │ ├── scopes │ │ └── main.py │ └── usage │ │ └── main.py ├── requirements-examples.txt ├── speech-to-text │ ├── rest │ │ ├── async │ │ │ ├── file │ │ │ │ ├── main.py │ │ │ │ └── preamble.wav │ │ │ └── url │ │ │ │ └── main.py │ │ ├── callback │ │ │ ├── README.md │ │ │ ├── callback │ │ │ │ ├── main.py │ │ │ │ └── preamble.wav │ │ │ └── endpoint │ │ │ │ ├── localhost.crt │ │ │ │ ├── localhost.csr │ │ │ │ ├── localhost.key │ │ │ │ └── main.py │ │ ├── intent │ │ │ ├── CallCenterPhoneCall.mp3 │ │ │ └── main.py │ │ ├── legacy_dict_url │ │ │ └── main.py │ │ ├── sentiment │ │ │ ├── CallCenterPhoneCall.mp3 │ │ │ └── main.py │ │ ├── stream_file │ │ │ ├── main.py │ │ │ └── preamble.wav │ │ ├── summary │ │ │ ├── CallCenterPhoneCall.mp3 │ │ │ └── main.py │ │ ├── sync │ │ │ ├── file │ │ │ │ ├── main.py │ │ │ │ └── preamble.wav │ │ │ └── url │ │ │ │ └── main.py │ │ └── topic │ │ │ ├── CallCenterPhoneCall.mp3 │ │ │ └── main.py │ └── websocket │ │ ├── async_http │ │ └── main.py │ │ ├── async_microphone │ │ ├── README.md │ │ └── main.py │ │ ├── http │ │ └── main.py │ │ ├── legacy_dict_microphone │ │ ├── README.md │ │ └── main.py │ │ ├── microphone │ │ ├── README.md │ │ └── main.py │ │ └── replay │ │ ├── main.py │ │ └── microsoft_headquarters.wav └── text-to-speech │ ├── rest │ ├── file │ │ ├── async_hello_world │ │ │ └── main.py │ │ ├── hello_world │ │ │ └── main.py │ │ ├── legacy_dict_hello_world │ │ │ └── main.py │ │ └── woodchuck │ │ │ └── main.py │ ├── memory │ │ ├── async_hello_world │ │ │ └── main.py │ │ └── hello_world │ │ │ └── main.py │ └── raw │ │ ├── async_hello_world │ │ └── main.py │ │ ├── hello_world │ │ └── main.py │ │ └── hello_world_play │ │ └── main.py │ └── websocket │ ├── async_simple │ └── main.py │ ├── output_to_wav │ └── main.py │ └── simple │ └── main.py ├── hack ├── check │ ├── check-mdlint.sh │ ├── check-shell.sh │ └── check-yaml.sh └── ensure-deps │ ├── ensure-actionlint.sh │ ├── ensure-dependencies.sh │ ├── ensure-diffutils.sh │ ├── ensure-gh-cli.sh │ ├── ensure-jq.sh │ ├── ensure-portaudio.sh │ └── ensure-shellcheck.sh ├── mypy.ini ├── pyproject.toml ├── requirements-dev.txt ├── requirements.txt ├── setup.py └── tests ├── __init__.py ├── daily_test ├── conversation.txt ├── preamble-rest.wav ├── preamble-websocket.wav ├── test_daily_async_listen_rest_file.py ├── test_daily_async_listen_rest_url.py ├── test_daily_async_listen_websocket.py ├── test_daily_async_read_rest_file.py ├── test_daily_async_speak_rest.py ├── test_daily_listen_rest_file.py ├── test_daily_listen_rest_url.py ├── test_daily_listen_websocket.py ├── test_daily_read_rest_file.py ├── test_daily_speak_rest.py └── testing-websocket.wav ├── edge_cases ├── auto_flush │ ├── async_microphone_mute │ │ └── main.py │ └── microphone_mute │ │ └── main.py ├── keepalive │ ├── async │ │ └── main.py │ └── sync │ │ └── main.py ├── reconnect_same_object │ ├── async │ │ └── main.py │ └── sync │ │ └── main.py └── usage_to_fast │ └── main.py ├── expected_failures └── exercise_timeout │ ├── async │ └── main.py │ └── sync │ └── main.py ├── response_data ├── listen │ ├── rest │ │ ├── a231370d439312b1a404bb6ad8de955e900ec8eae9a906329af8cc672e6ec7ba-29e7c8100617f70da4ae9da1921cb5071a01219f4780ca70930b0a370ed2163a-options.json │ │ ├── a231370d439312b1a404bb6ad8de955e900ec8eae9a906329af8cc672e6ec7ba-29e7c8100617f70da4ae9da1921cb5071a01219f4780ca70930b0a370ed2163a-response.json │ │ ├── a231370d439312b1a404bb6ad8de955e900ec8eae9a906329af8cc672e6ec7ba-29e7c8100617f70da4ae9da1921cb5071a01219f4780ca70930b0a370ed2163a.cmd │ │ ├── a231370d439312b1a404bb6ad8de955e900ec8eae9a906329af8cc672e6ec7ba-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76-error.json │ │ ├── a231370d439312b1a404bb6ad8de955e900ec8eae9a906329af8cc672e6ec7ba-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76-options.json │ │ ├── a231370d439312b1a404bb6ad8de955e900ec8eae9a906329af8cc672e6ec7ba-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76-response.json │ │ ├── a231370d439312b1a404bb6ad8de955e900ec8eae9a906329af8cc672e6ec7ba-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76.cmd │ │ ├── b00dc103a62ea2ccfc752ec0f646c7528ef5e729a9d7481d2a944253a9128ce2-29e7c8100617f70da4ae9da1921cb5071a01219f4780ca70930b0a370ed2163a-options.json │ │ ├── b00dc103a62ea2ccfc752ec0f646c7528ef5e729a9d7481d2a944253a9128ce2-29e7c8100617f70da4ae9da1921cb5071a01219f4780ca70930b0a370ed2163a-response.json │ │ ├── b00dc103a62ea2ccfc752ec0f646c7528ef5e729a9d7481d2a944253a9128ce2-29e7c8100617f70da4ae9da1921cb5071a01219f4780ca70930b0a370ed2163a.cmd │ │ ├── b00dc103a62ea2ccfc752ec0f646c7528ef5e729a9d7481d2a944253a9128ce2-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76-options.json │ │ ├── b00dc103a62ea2ccfc752ec0f646c7528ef5e729a9d7481d2a944253a9128ce2-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76-response.json │ │ ├── b00dc103a62ea2ccfc752ec0f646c7528ef5e729a9d7481d2a944253a9128ce2-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76.cmd │ │ ├── c4e1c0031174878d8f0e3dbd87916ee16d56f1c610ac525af5712ea37226a455-29e7c8100617f70da4ae9da1921cb5071a01219f4780ca70930b0a370ed2163a-options.json │ │ ├── c4e1c0031174878d8f0e3dbd87916ee16d56f1c610ac525af5712ea37226a455-29e7c8100617f70da4ae9da1921cb5071a01219f4780ca70930b0a370ed2163a-response.json │ │ ├── c4e1c0031174878d8f0e3dbd87916ee16d56f1c610ac525af5712ea37226a455-29e7c8100617f70da4ae9da1921cb5071a01219f4780ca70930b0a370ed2163a.cmd │ │ ├── c4e1c0031174878d8f0e3dbd87916ee16d56f1c610ac525af5712ea37226a455-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76-error.json │ │ ├── c4e1c0031174878d8f0e3dbd87916ee16d56f1c610ac525af5712ea37226a455-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76-options.json │ │ ├── c4e1c0031174878d8f0e3dbd87916ee16d56f1c610ac525af5712ea37226a455-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76-response.json │ │ ├── c4e1c0031174878d8f0e3dbd87916ee16d56f1c610ac525af5712ea37226a455-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76.cmd │ │ ├── f3b6208a662156067a41bddd295a1a0a53ea34a268e27a8f1a9d7107aa99732f-29e7c8100617f70da4ae9da1921cb5071a01219f4780ca70930b0a370ed2163a-options.json │ │ ├── f3b6208a662156067a41bddd295a1a0a53ea34a268e27a8f1a9d7107aa99732f-29e7c8100617f70da4ae9da1921cb5071a01219f4780ca70930b0a370ed2163a-response.json │ │ ├── f3b6208a662156067a41bddd295a1a0a53ea34a268e27a8f1a9d7107aa99732f-29e7c8100617f70da4ae9da1921cb5071a01219f4780ca70930b0a370ed2163a.cmd │ │ ├── f3b6208a662156067a41bddd295a1a0a53ea34a268e27a8f1a9d7107aa99732f-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76-error.json │ │ ├── f3b6208a662156067a41bddd295a1a0a53ea34a268e27a8f1a9d7107aa99732f-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76-options.json │ │ ├── f3b6208a662156067a41bddd295a1a0a53ea34a268e27a8f1a9d7107aa99732f-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76-response.json │ │ └── f3b6208a662156067a41bddd295a1a0a53ea34a268e27a8f1a9d7107aa99732f-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76.cmd │ └── websocket │ │ ├── a6d1b12d5ce73a51a7b69ab156f0c98c72cdc1cfcf4a25f7b634c328cce4d760-42fc5ed98cabc1fa1a2f276301c27c46dd15f6f5187cd93d944cc94fa81c8469-options.json │ │ ├── a6d1b12d5ce73a51a7b69ab156f0c98c72cdc1cfcf4a25f7b634c328cce4d760-42fc5ed98cabc1fa1a2f276301c27c46dd15f6f5187cd93d944cc94fa81c8469-response.json │ │ ├── a6d1b12d5ce73a51a7b69ab156f0c98c72cdc1cfcf4a25f7b634c328cce4d760-42fc5ed98cabc1fa1a2f276301c27c46dd15f6f5187cd93d944cc94fa81c8469.cmd │ │ ├── a6d1b12d5ce73a51a7b69ab156f0c98c72cdc1cfcf4a25f7b634c328cce4d760-d7334c26cf6468c191e05ff5e8151da9b67985c66ab177e9446fd14bbafd70df-options.json │ │ ├── a6d1b12d5ce73a51a7b69ab156f0c98c72cdc1cfcf4a25f7b634c328cce4d760-d7334c26cf6468c191e05ff5e8151da9b67985c66ab177e9446fd14bbafd70df-response.json │ │ └── a6d1b12d5ce73a51a7b69ab156f0c98c72cdc1cfcf4a25f7b634c328cce4d760-d7334c26cf6468c191e05ff5e8151da9b67985c66ab177e9446fd14bbafd70df.cmd ├── read │ └── rest │ │ ├── 3917a1c81c08e360c0d4bba0ff9ebd645e610e4149483e5f2888a2c5df388b37-23e873efdfd4d680286fda14ff8f10864218311e79efc92ecc82bce3e574c366-error.json │ │ ├── 3917a1c81c08e360c0d4bba0ff9ebd645e610e4149483e5f2888a2c5df388b37-23e873efdfd4d680286fda14ff8f10864218311e79efc92ecc82bce3e574c366-options.json │ │ ├── 3917a1c81c08e360c0d4bba0ff9ebd645e610e4149483e5f2888a2c5df388b37-23e873efdfd4d680286fda14ff8f10864218311e79efc92ecc82bce3e574c366-response.json │ │ └── 3917a1c81c08e360c0d4bba0ff9ebd645e610e4149483e5f2888a2c5df388b37-23e873efdfd4d680286fda14ff8f10864218311e79efc92ecc82bce3e574c366.cmd └── speak │ └── rest │ ├── 18144fa7f4709bc9972c24d0addc8faa360dca933e7e0027b062e57b7c41f426-f8c3bf62a9aa3e6fc1619c250e48abe7519373d3edf41be62eb5dc45199af2ef-options.json │ ├── 18144fa7f4709bc9972c24d0addc8faa360dca933e7e0027b062e57b7c41f426-f8c3bf62a9aa3e6fc1619c250e48abe7519373d3edf41be62eb5dc45199af2ef-response.json │ ├── 18144fa7f4709bc9972c24d0addc8faa360dca933e7e0027b062e57b7c41f426-f8c3bf62a9aa3e6fc1619c250e48abe7519373d3edf41be62eb5dc45199af2ef.cmd │ ├── 18144fa7f4709bc9972c24d0addc8faa360dca933e7e0027b062e57b7c41f426-f8c3bf62a9aa3e6fc1619c250e48abe7519373d3edf41be62eb5dc45199af2ef.wav │ ├── 1fe0ad339338a9d6cffbab2c7ace41ba5387b5fe7906854795702dce91034fd3-f8c3bf62a9aa3e6fc1619c250e48abe7519373d3edf41be62eb5dc45199af2ef-options.json │ ├── 1fe0ad339338a9d6cffbab2c7ace41ba5387b5fe7906854795702dce91034fd3-f8c3bf62a9aa3e6fc1619c250e48abe7519373d3edf41be62eb5dc45199af2ef-response.json │ ├── 1fe0ad339338a9d6cffbab2c7ace41ba5387b5fe7906854795702dce91034fd3-f8c3bf62a9aa3e6fc1619c250e48abe7519373d3edf41be62eb5dc45199af2ef.cmd │ └── 1fe0ad339338a9d6cffbab2c7ace41ba5387b5fe7906854795702dce91034fd3-f8c3bf62a9aa3e6fc1619c250e48abe7519373d3edf41be62eb5dc45199af2ef.wav ├── unit_test ├── conversation.txt ├── preamble-rest.wav ├── preamble-websocket.wav ├── test_unit_async_listen_rest_file.py ├── test_unit_async_listen_rest_url.py ├── test_unit_async_listen_websocket.py ├── test_unit_async_read_rest_file.py ├── test_unit_async_speak_rest.py ├── test_unit_listen_rest_file.py ├── test_unit_listen_rest_url.py ├── test_unit_listen_websocket.py ├── test_unit_read_rest_file.py └── test_unit_speak_rest.py └── utils ├── __init__.py ├── test_utils.py └── utils.py /.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | # See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/python-3/.devcontainer/base.Dockerfile 2 | 3 | # [Choice] Python version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.10, 3.9, 3.8, 3.7, 3.6, 3-bullseye, 3.10-bullseye, 3.9-bullseye, 3.8-bullseye, 3.7-bullseye, 3.6-bullseye, 3-buster, 3.10-buster, 3.9-buster, 3.8-buster, 3.7-buster, 3.6-buster 4 | ARG VARIANT="3.10-bullseye" 5 | FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT} 6 | 7 | # [Choice] Node.js version: none, lts/*, 16, 14, 12, 10 8 | ARG NODE_VERSION="none" 9 | RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi 10 | 11 | # [Optional] If your pip requirements rarely change, uncomment this section to add them to the image. 12 | # COPY requirements.txt /tmp/pip-tmp/ 13 | # RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \ 14 | # && rm -rf /tmp/pip-tmp 15 | 16 | # [Optional] Uncomment this section to install additional OS packages. 17 | # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ 18 | # && apt-get -y install --no-install-recommends 19 | 20 | # [Optional] Uncomment this line to install global node packages. 21 | # RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g " 2>&1 -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | // For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: 2 | // https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/python-3 3 | { 4 | "name": "Python 3", 5 | "build": { 6 | "dockerfile": "Dockerfile", 7 | "context": "..", 8 | "args": { 9 | // Update 'VARIANT' to pick a Python version: 3, 3.10, 3.9, 3.8, 3.7, 3.6 10 | // Append -bullseye or -buster to pin to an OS version. 11 | // Use -bullseye variants on local on arm64/Apple Silicon. 12 | "VARIANT": "3.10-bullseye", 13 | // Options 14 | "NODE_VERSION": "none" 15 | } 16 | }, 17 | 18 | // Configure tool-specific properties. 19 | "customizations": { 20 | // Configure properties specific to VS Code. 21 | "vscode": { 22 | // Set *default* container specific settings.json values on container create. 23 | "settings": { 24 | "python.defaultInterpreterPath": "/usr/local/bin/python", 25 | "python.linting.enabled": true, 26 | "python.linting.pylintEnabled": true, 27 | "python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8", 28 | "python.formatting.blackPath": "/usr/local/py-utils/bin/black", 29 | "python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf", 30 | "python.linting.banditPath": "/usr/local/py-utils/bin/bandit", 31 | "python.linting.flake8Path": "/usr/local/py-utils/bin/flake8", 32 | "python.linting.mypyPath": "/usr/local/py-utils/bin/mypy", 33 | "python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle", 34 | "python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle", 35 | "python.linting.pylintPath": "/usr/local/py-utils/bin/pylint" 36 | }, 37 | 38 | // Add the IDs of extensions you want installed when the container is created. 39 | "extensions": [ 40 | "ms-python.python", 41 | "ms-python.vscode-pylance" 42 | ] 43 | } 44 | }, 45 | 46 | // Use 'forwardPorts' to make a list of ports inside the container available locally. 47 | // "forwardPorts": [], 48 | 49 | // Use 'postCreateCommand' to run commands after the container is created. 50 | // "postCreateCommand": "pip3 install --user -r requirements.txt", 51 | 52 | // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. 53 | "remoteUser": "vscode" 54 | } 55 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | DG_API_KEY="" 2 | DG_PROJECT_ID="" 3 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Something is occurring that I think is wrong 4 | title: '' 5 | labels: "\U0001F41B bug" 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## What is the current behavior? 11 | 14 | 15 | 16 | ## Steps to reproduce 17 | 20 | 21 | 22 | ## Expected behavior 23 | 26 | 27 | 28 | ## Please tell us about your environment 29 | 35 | 36 | 37 | ## Other information 38 | 41 | 42 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Deepgram Developer Community 4 | url: https://github.com/orgs/deepgram/discussions 5 | - name: Deepgram on Twitter 6 | url: https://twitter.com/DeepgramAI 7 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature Request 3 | about: I think X would be a cool addition or change. 4 | title: '' 5 | labels: "✨ enhancement" 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Proposed changes 11 | 14 | 15 | 16 | ## Context 17 | 20 | 21 | 22 | ## Possible Implementation 23 | 26 | 27 | 28 | ## Other information 29 | 32 | 33 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Proposed changes 2 | 5 | 6 | 7 | ## Types of changes 8 | 9 | What types of changes does your code introduce to the community Python SDK? 10 | _Put an `x` in the boxes that apply_ 11 | 12 | - [ ] Bugfix (non-breaking change which fixes an issue) 13 | - [ ] New feature (non-breaking change which adds functionality) 14 | - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) 15 | - [ ] Documentation update or tests (if none of the other choices apply) 16 | 17 | ## Checklist 18 | 19 | _Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code._ 20 | 21 | - [ ] I have read the [CONTRIBUTING](../CONTRIBUTING.md) doc 22 | - [ ] I have lint'ed all of my code using repo standards 23 | - [ ] I have added tests that prove my fix is effective or that my feature works 24 | - [ ] I have added necessary documentation (if appropriate) 25 | 26 | ## Further comments 27 | 30 | 31 | -------------------------------------------------------------------------------- /.github/images/git_workflow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deepgram/deepgram-python-sdk/6380b56f810b31323aedf7b644c5a0466f48a1ee/.github/images/git_workflow.png -------------------------------------------------------------------------------- /.github/workflows/CD-dev.yml: -------------------------------------------------------------------------------- 1 | name: CD - Publish Development Releases 2 | 3 | on: 4 | push: 5 | branches: 6 | - "!not_activated_on_branches!*" 7 | tags: 8 | - "v[0-9]+.[0-9]+.[0-9]+-dev.[0-9]+" 9 | 10 | jobs: 11 | build: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v4 15 | - uses: actions/setup-python@v4 16 | with: 17 | python-version: '3.10' 18 | 19 | - name: Update Version in __init__.py 20 | run: | 21 | sed -i 's/0.0.0/${{ github.ref_name }}/g' ./deepgram/__init__.py 22 | sed -i 's/name = "deepgram-sdk"/name = "deepgram-unstable-sdk"/g' ./pyproject.toml 23 | sed -i 's/name="deepgram-sdk"/name="deepgram-unstable-sdk"/g' ./setup.py 24 | 25 | - name: Install Dependencies 26 | run: pip install . 27 | 28 | #- name: Run Tests 29 | # run: pytest tests/ 30 | 31 | - name: Install build 32 | run: python -m pip install --upgrade build 33 | 34 | - name: Build SDK 35 | run: python -m build 36 | 37 | - name: Install twine 38 | run: python -m pip install --upgrade twine 39 | 40 | - name: Publish to PyPi 41 | uses: pypa/gh-action-pypi-publish@release/v1 42 | with: 43 | password: ${{ secrets.PYPI_DEV_API_TOKEN }} 44 | -------------------------------------------------------------------------------- /.github/workflows/CD.yaml: -------------------------------------------------------------------------------- 1 | name: CD - Publish Releases 2 | 3 | on: 4 | release: 5 | types: [ published ] 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v3 12 | - uses: actions/setup-python@v4 13 | with: 14 | python-version: '3.10' 15 | 16 | - name: Update Version in __init__.py 17 | run: sed -i 's/0.0.0/${{ github.event.release.tag_name }}/g' ./deepgram/__init__.py 18 | 19 | - name: Install Dependencies 20 | run: pip install . 21 | 22 | #- name: Run Tests 23 | # run: pytest tests/ 24 | 25 | - name: Install build 26 | run: python -m pip install --upgrade build 27 | 28 | - name: Build SDK 29 | run: python -m build 30 | 31 | - name: Install twine 32 | run: python -m pip install --upgrade twine 33 | 34 | - name: Publish to PyPi 35 | uses: pypa/gh-action-pypi-publish@release/v1 36 | with: 37 | password: ${{ secrets.PYPI_API_TOKEN }} 38 | -------------------------------------------------------------------------------- /.github/workflows/CI.yaml: -------------------------------------------------------------------------------- 1 | name: CI - Build SDK 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v3 14 | - uses: actions/setup-python@v4 15 | with: 16 | python-version: '3.10' 17 | 18 | - name: Install Dependencies 19 | run: pip install . 20 | 21 | #- name: Run Tests 22 | # run: pytest tests/ 23 | 24 | - name: Check SDK Setup 25 | run: python -m pip install --upgrade build 26 | 27 | - name: Build SDK 28 | run: python -m build 29 | -------------------------------------------------------------------------------- /.github/workflows/check-actionlint.yaml: -------------------------------------------------------------------------------- 1 | name: Check - actionlint 2 | 3 | on: 4 | pull_request: 5 | types: 6 | - assigned 7 | - opened 8 | - synchronize 9 | - reopened 10 | paths: 11 | - ".github/workflows/**" 12 | 13 | jobs: 14 | checkactionlint: 15 | name: Check actionlint 16 | # Only run this job if we're in the main repo, not a fork. 17 | if: github.repository == 'deepgram/deepgram-python-sdk' 18 | runs-on: ubuntu-latest 19 | steps: 20 | 21 | - name: Checkout code by commit 22 | uses: actions/checkout@v4 23 | 24 | - name: Ensure dependencies installed 25 | shell: bash 26 | run: | 27 | make ensure-deps 28 | 29 | - name: Run actionlint 30 | run: | 31 | make actionlint 32 | -------------------------------------------------------------------------------- /.github/workflows/check-all.yaml: -------------------------------------------------------------------------------- 1 | name: Check - All linters, etc 2 | on: 3 | push: 4 | branches: 5 | - main 6 | - release-* 7 | tags-ignore: 8 | - "**" 9 | 10 | jobs: 11 | build: 12 | name: Change to Main/Release Branch 13 | # Only run this job if we're in the main repo, not a fork. 14 | if: github.repository == 'deepgram/deepgram-python-sdk' 15 | runs-on: ubuntu-latest 16 | steps: 17 | 18 | - name: Checkout code by commit 19 | uses: actions/checkout@v4 20 | 21 | - uses: actions/setup-python@v4 22 | with: 23 | python-version: '3.10' 24 | 25 | - name: Ensure dependencies installed 26 | shell: bash 27 | run: | 28 | make ensure-deps 29 | 30 | - name: Install Dependencies 31 | run: | 32 | pip install -r requirements.txt 33 | pip install -r requirements-dev.txt 34 | pip install -r examples/requirements-examples.txt 35 | 36 | - name: Run all checks 37 | shell: bash 38 | run: | 39 | make check 40 | -------------------------------------------------------------------------------- /.github/workflows/check-lint.yaml: -------------------------------------------------------------------------------- 1 | name: Check - lint 2 | 3 | on: 4 | pull_request: 5 | types: 6 | - assigned 7 | - opened 8 | - synchronize 9 | - reopened 10 | paths: 11 | - "deepgram/**.py" 12 | 13 | jobs: 14 | checklint: 15 | name: Check shell 16 | # Only run this job if we're in the main repo, not a fork. 17 | if: github.repository == 'deepgram/deepgram-python-sdk' 18 | runs-on: ubuntu-latest 19 | steps: 20 | 21 | - name: Checkout code by commit 22 | uses: actions/checkout@v4 23 | 24 | - uses: actions/setup-python@v4 25 | with: 26 | python-version: '3.10' 27 | 28 | - name: Ensure dependencies installed 29 | shell: bash 30 | run: | 31 | make ensure-deps 32 | 33 | - name: Install Dependencies 34 | run: | 35 | pip install -r requirements.txt 36 | pip install -r requirements-dev.txt 37 | pip install -r examples/requirements-examples.txt 38 | 39 | - name: Run mdlint 40 | run: | 41 | make lint 42 | -------------------------------------------------------------------------------- /.github/workflows/check-mdlint.yaml: -------------------------------------------------------------------------------- 1 | name: Check - mdlint 2 | 3 | on: 4 | pull_request: 5 | types: 6 | - assigned 7 | - opened 8 | - synchronize 9 | - reopened 10 | paths: 11 | - "**.md" 12 | - "hack/check/check-mdlint.sh" 13 | 14 | jobs: 15 | checkmdlint: 16 | name: Check mdlint 17 | # Only run this job if we're in the main repo, not a fork. 18 | if: github.repository == 'deepgram/deepgram-python-sdk' 19 | runs-on: ubuntu-latest 20 | steps: 21 | 22 | - name: Checkout code by commit 23 | uses: actions/checkout@v4 24 | 25 | - name: Ensure dependencies installed 26 | shell: bash 27 | run: | 28 | make ensure-deps 29 | 30 | - name: Run mdlint 31 | run: | 32 | make mdlint 33 | -------------------------------------------------------------------------------- /.github/workflows/check-shell.yaml: -------------------------------------------------------------------------------- 1 | name: Check - shell 2 | 3 | on: 4 | pull_request: 5 | types: 6 | - assigned 7 | - opened 8 | - synchronize 9 | - reopened 10 | paths: 11 | - "**/Makefile" 12 | - "**.sh" 13 | - "hack/check/check-shell.sh" 14 | 15 | jobs: 16 | checkshell: 17 | name: Check shell 18 | # Only run this job if we're in the main repo, not a fork. 19 | if: github.repository == 'deepgram/deepgram-python-sdk' 20 | runs-on: ubuntu-latest 21 | steps: 22 | 23 | - name: Checkout code by commit 24 | uses: actions/checkout@v4 25 | 26 | - name: Ensure dependencies installed 27 | shell: bash 28 | run: | 29 | make ensure-deps 30 | 31 | - name: Run shellcheck 32 | run: | 33 | make shellcheck 34 | -------------------------------------------------------------------------------- /.github/workflows/check-static.yaml: -------------------------------------------------------------------------------- 1 | name: Check - static 2 | 3 | on: 4 | pull_request: 5 | types: 6 | - assigned 7 | - opened 8 | - synchronize 9 | - reopened 10 | paths: 11 | - "deepgram/**.py" 12 | 13 | jobs: 14 | checkstatic: 15 | name: Check static 16 | # Only run this job if we're in the main repo, not a fork. 17 | if: github.repository == 'deepgram/deepgram-python-sdk' 18 | runs-on: ubuntu-latest 19 | steps: 20 | 21 | - name: Checkout code by commit 22 | uses: actions/checkout@v4 23 | 24 | - uses: actions/setup-python@v4 25 | with: 26 | python-version: '3.10' 27 | 28 | - name: Ensure dependencies installed 29 | shell: bash 30 | run: | 31 | make ensure-deps 32 | 33 | - name: Install Dependencies 34 | run: | 35 | pip install -r requirements.txt 36 | pip install -r requirements-dev.txt 37 | pip install -r examples/requirements-examples.txt 38 | 39 | - name: Run mdlint 40 | run: | 41 | make static 42 | -------------------------------------------------------------------------------- /.github/workflows/check-yaml.yaml: -------------------------------------------------------------------------------- 1 | name: Check - yaml 2 | 3 | on: 4 | pull_request: 5 | types: 6 | - assigned 7 | - opened 8 | - synchronize 9 | - reopened 10 | paths: 11 | - ".github/workflows/**" 12 | 13 | jobs: 14 | checkmdlint: 15 | name: Check mdlint 16 | # Only run this job if we're in the main repo, not a fork. 17 | if: github.repository == 'deepgram/deepgram-python-sdk' 18 | runs-on: ubuntu-latest 19 | steps: 20 | 21 | - name: Checkout code by commit 22 | uses: actions/checkout@v4 23 | 24 | - name: Ensure dependencies installed 25 | shell: bash 26 | run: | 27 | make ensure-deps 28 | 29 | - name: Run mdlint 30 | run: | 31 | make mdlint 32 | -------------------------------------------------------------------------------- /.github/workflows/tests-daily.yaml: -------------------------------------------------------------------------------- 1 | name: Test - Daily 2 | 3 | on: 4 | workflow_dispatch: 5 | repository_dispatch: 6 | types: 7 | - manual-daily-text 8 | schedule: 9 | - cron: "0 9 * * *" 10 | 11 | jobs: 12 | daily-tests: 13 | name: Daily Tests 14 | # Only run this job if we're in the main repo, not a fork. 15 | if: github.repository == 'deepgram/deepgram-python-sdk' 16 | runs-on: ubuntu-latest 17 | permissions: 18 | contents: write 19 | pull-requests: write 20 | timeout-minutes: 30 21 | steps: 22 | 23 | - name: Checkout code by commit 24 | uses: actions/checkout@v4 25 | 26 | - uses: actions/setup-python@v4 27 | with: 28 | python-version: '3.10' 29 | 30 | - name: Config git 31 | env: 32 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 33 | shell: bash 34 | run: | 35 | git config --global user.name "github-actions[bot]" 36 | git config --global user.email "github-actions[bot]@users.noreply.github.com" 37 | git config --global init.defaultBranch main 38 | git config --global pull.rebase true 39 | git config --global url."https://git:$GITHUB_TOKEN@github.com".insteadOf "https://github.com" 40 | 41 | - name: Get dependencies 42 | shell: bash 43 | run: | 44 | make ensure-deps 45 | 46 | - name: Install Dependencies 47 | run: | 48 | pip install --upgrade pip 49 | pip install -r requirements.txt 50 | pip install -r requirements-dev.txt 51 | pip install -e . 52 | 53 | - name: Run all checks 54 | shell: bash 55 | env: 56 | DEEPGRAM_API_KEY: ${{ secrets.GH_ASR_TESTS_API_KEY_PUBLIC_R }} 57 | run: | 58 | make daily-test 59 | 60 | - name: Get dependencies 61 | shell: bash 62 | env: 63 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 64 | run: | 65 | BRANCH_NAME="response-shape-${{ github.run_id }}" 66 | git checkout -b "$BRANCH_NAME" 67 | 68 | # create a PR 69 | git add ./tests/response_data 70 | git commit -s -m "auto-generated - update Response Shapes" 71 | git push origin "$BRANCH_NAME" 72 | gh pr create --title "auto-generated - update Response Shapes" --body "auto-generated - update Response Shapes" --base "main" --head "$BRANCH_NAME" 73 | sleep 10 74 | gh pr merge "$BRANCH_NAME" --delete-branch --squash --admin 75 | -------------------------------------------------------------------------------- /.github/workflows/tests-unit.yaml: -------------------------------------------------------------------------------- 1 | name: Test - Unit 2 | 3 | on: 4 | pull_request: 5 | types: 6 | - assigned 7 | - opened 8 | - synchronize 9 | - reopened 10 | jobs: 11 | build: 12 | name: Unit Tests 13 | # Only run this job if we're in the main repo, not a fork. 14 | if: github.repository == 'deepgram/deepgram-python-sdk' 15 | runs-on: ubuntu-latest 16 | timeout-minutes: 5 17 | steps: 18 | 19 | - name: Checkout code by commit 20 | uses: actions/checkout@v4 21 | 22 | - uses: actions/setup-python@v4 23 | with: 24 | python-version: '3.10' 25 | 26 | - name: Install Dependencies 27 | run: | 28 | pip install --upgrade pip 29 | pip install -r requirements.txt 30 | pip install -r requirements-dev.txt 31 | pip install -e . 32 | 33 | - name: Run all checks 34 | shell: bash 35 | env: 36 | DEEPGRAM_API_KEY: ${{ secrets.GH_ASR_TESTS_API_KEY_PUBLIC_R }} 37 | run: | 38 | make unit-test 39 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # general 2 | 3 | # environment artifacts 4 | .venv 5 | .env 6 | venv/ 7 | venv.bak/ 8 | .vscode/ 9 | .DS_Store 10 | Pipfile 11 | Pipfile.lock 12 | 13 | # python artifacts 14 | __pycache__ 15 | *.egg-info 16 | dist/ 17 | .mypy_cache/ 18 | .pytest_cache/ 19 | 20 | # build 21 | build/ 22 | poetry.lock 23 | 24 | # examples 25 | chatlog.txt 26 | output_*.wav 27 | -------------------------------------------------------------------------------- /.markdownlintrc: -------------------------------------------------------------------------------- 1 | { 2 | "default": true, 3 | "line_length": false, 4 | "MD024": { "allow_different_nesting": true }, 5 | "MD026": { "punctuation": ".,;:!" }, 6 | "MD046": { "style": "fenced" } 7 | } 8 | -------------------------------------------------------------------------------- /.yamllintconfig.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | extends: relaxed 3 | 4 | rules: 5 | line-length: disable 6 | trailing-spaces: enable 7 | new-line-at-end-of-file: enable 8 | new-lines: 9 | type: unix 10 | indentation: disable 11 | key-duplicates: disable 12 | empty-lines: enable 13 | colons: disable 14 | commas: disable 15 | 16 | ignore: | 17 | /deepgram-python-sdk/.github/ISSUE_TEMPLATE/config.yml 18 | /deepgram-python-sdk/addons/**/*/ 19 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | Please see the [Code of Conduct](https://github.com/deepgram/deepgram-python-sdk/blob/main/.github/CODE_OF_CONDUCT.md) at [https://github.com/deepgram/deepgram-python-sdk/blob/main/.github/CODE_OF_CONDUCT.md](https://github.com/deepgram/deepgram-python-sdk/blob/main/.github/CODE_OF_CONDUCT.md). 4 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | Please see the [Contributing Guidelines](https://github.com/deepgram/deepgram-python-sdk/blob/main/.github/CONTRIBUTING.md) at [https://github.com/deepgram/deepgram-python-sdk/blob/main/.github/CONTRIBUTING.md](https://github.com/deepgram/deepgram-python-sdk/blob/main/.github/CONTRIBUTING.md). 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 deepgram 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /deepgram/audio/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from .microphone import Microphone 6 | from .microphone import DeepgramMicrophoneError 7 | from .microphone import ( 8 | LOGGING as INPUT_LOGGING, 9 | CHANNELS as INPUT_CHANNELS, 10 | RATE as INPUT_RATE, 11 | CHUNK as INPUT_CHUNK, 12 | ) 13 | 14 | from .speaker import Speaker 15 | from .speaker import DeepgramSpeakerError 16 | from .speaker import ( 17 | LOGGING as OUTPUT_LOGGING, 18 | CHANNELS as OUTPUT_CHANNELS, 19 | RATE as OUTPUT_RATE, 20 | CHUNK as OUTPUT_CHUNK, 21 | PLAYBACK_DELTA as OUTPUT_PLAYBACK_DELTA, 22 | ) 23 | -------------------------------------------------------------------------------- /deepgram/audio/microphone/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from .microphone import Microphone 6 | from .constants import LOGGING, CHANNELS, RATE, CHUNK 7 | from .errors import DeepgramMicrophoneError 8 | -------------------------------------------------------------------------------- /deepgram/audio/microphone/constants.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from ...utils import verboselogs 6 | 7 | # Constants for microphone 8 | LOGGING = verboselogs.WARNING 9 | CHANNELS = 1 10 | RATE = 16000 11 | CHUNK = 8194 12 | -------------------------------------------------------------------------------- /deepgram/audio/microphone/errors.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | 6 | # exceptions for microphone 7 | class DeepgramMicrophoneError(Exception): 8 | """ 9 | Exception raised for known errors related to Microphone library. 10 | 11 | Attributes: 12 | message (str): The error message describing the exception. 13 | """ 14 | 15 | def __init__(self, message: str): 16 | super().__init__(message) 17 | self.name = "DeepgramMicrophoneError" 18 | self.message = message 19 | 20 | def __str__(self): 21 | return f"{self.name}: {self.message}" 22 | -------------------------------------------------------------------------------- /deepgram/audio/speaker/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from .speaker import Speaker 6 | from .errors import DeepgramSpeakerError 7 | from .constants import LOGGING, CHANNELS, RATE, CHUNK, PLAYBACK_DELTA 8 | -------------------------------------------------------------------------------- /deepgram/audio/speaker/constants.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from ...utils import verboselogs 6 | 7 | # Constants for speaker 8 | LOGGING = verboselogs.WARNING 9 | TIMEOUT = 0.050 10 | CHANNELS = 1 11 | RATE = 16000 12 | CHUNK = 8194 13 | 14 | # Constants for speaker 15 | PLAYBACK_DELTA = 2000 16 | -------------------------------------------------------------------------------- /deepgram/audio/speaker/errors.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | 6 | # exceptions for speaker 7 | class DeepgramSpeakerError(Exception): 8 | """ 9 | Exception raised for known errors related to Speaker library. 10 | 11 | Attributes: 12 | message (str): The error message describing the exception. 13 | """ 14 | 15 | def __init__(self, message: str): 16 | super().__init__(message) 17 | self.name = "DeepgramSpeakerError" 18 | self.message = message 19 | 20 | def __str__(self): 21 | return f"{self.name}: {self.message}" 22 | -------------------------------------------------------------------------------- /deepgram/clients/agent/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from .enums import AgentWebSocketEvents 6 | 7 | # websocket 8 | from .client import ( 9 | AgentWebSocketClient, 10 | AsyncAgentWebSocketClient, 11 | ) 12 | 13 | from .client import ( 14 | #### common websocket response 15 | OpenResponse, 16 | CloseResponse, 17 | ErrorResponse, 18 | UnhandledResponse, 19 | #### unique 20 | WelcomeResponse, 21 | SettingsAppliedResponse, 22 | ConversationTextResponse, 23 | UserStartedSpeakingResponse, 24 | AgentThinkingResponse, 25 | FunctionCallRequest, 26 | AgentStartedSpeakingResponse, 27 | AgentAudioDoneResponse, 28 | InjectionRefusedResponse, 29 | ) 30 | 31 | from .client import ( 32 | # top level 33 | SettingsOptions, 34 | UpdatePromptOptions, 35 | UpdateSpeakOptions, 36 | InjectAgentMessageOptions, 37 | FunctionCallResponse, 38 | AgentKeepAlive, 39 | # sub level 40 | Listen, 41 | ListenProvider, 42 | Speak, 43 | SpeakProvider, 44 | Header, 45 | Item, 46 | Properties, 47 | Parameters, 48 | Function, 49 | Think, 50 | ThinkProvider, 51 | Agent, 52 | Input, 53 | Output, 54 | Audio, 55 | Endpoint, 56 | ) 57 | -------------------------------------------------------------------------------- /deepgram/clients/agent/enums.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from aenum import StrEnum 6 | 7 | # Constants mapping to events from the Deepgram API 8 | 9 | 10 | class AgentWebSocketEvents(StrEnum): 11 | """ 12 | Enumerates the possible Agent API events that can be received from the Deepgram API 13 | """ 14 | 15 | # server 16 | Open: str = "Open" 17 | Close: str = "Close" 18 | AudioData: str = "AudioData" 19 | Welcome: str = "Welcome" 20 | SettingsApplied: str = "SettingsApplied" 21 | ConversationText: str = "ConversationText" 22 | UserStartedSpeaking: str = "UserStartedSpeaking" 23 | AgentThinking: str = "AgentThinking" 24 | FunctionCallRequest: str = "FunctionCallRequest" 25 | AgentStartedSpeaking: str = "AgentStartedSpeaking" 26 | AgentAudioDone: str = "AgentAudioDone" 27 | Error: str = "Error" 28 | Unhandled: str = "Unhandled" 29 | 30 | # client 31 | Settings: str = "Settings" 32 | UpdatePrompt: str = "UpdatePrompt" 33 | UpdateSpeak: str = "UpdateSpeak" 34 | InjectAgentMessage: str = "InjectAgentMessage" 35 | InjectionRefused: str = "InjectionRefused" 36 | AgentKeepAlive: str = "AgentKeepAlive" 37 | -------------------------------------------------------------------------------- /deepgram/clients/agent/v1/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | # common websocket 6 | from ...common import ( 7 | OpenResponse, 8 | CloseResponse, 9 | UnhandledResponse, 10 | ErrorResponse, 11 | ) 12 | 13 | # websocket 14 | from .websocket import AgentWebSocketClient, AsyncAgentWebSocketClient 15 | 16 | from .websocket import ( 17 | #### common websocket response 18 | BaseResponse, 19 | OpenResponse, 20 | CloseResponse, 21 | ErrorResponse, 22 | UnhandledResponse, 23 | #### unique 24 | WelcomeResponse, 25 | SettingsAppliedResponse, 26 | ConversationTextResponse, 27 | UserStartedSpeakingResponse, 28 | AgentThinkingResponse, 29 | FunctionCallRequest, 30 | AgentStartedSpeakingResponse, 31 | AgentAudioDoneResponse, 32 | InjectionRefusedResponse, 33 | ) 34 | 35 | from .websocket import ( 36 | # top level 37 | SettingsOptions, 38 | UpdatePromptOptions, 39 | UpdateSpeakOptions, 40 | InjectAgentMessageOptions, 41 | FunctionCallResponse, 42 | AgentKeepAlive, 43 | # sub level 44 | Listen, 45 | ListenProvider, 46 | Speak, 47 | SpeakProvider, 48 | Header, 49 | Item, 50 | Properties, 51 | Parameters, 52 | Function, 53 | Think, 54 | ThinkProvider, 55 | Agent, 56 | Input, 57 | Output, 58 | Audio, 59 | Endpoint, 60 | ) 61 | -------------------------------------------------------------------------------- /deepgram/clients/agent/v1/websocket/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from .client import AgentWebSocketClient 6 | from .async_client import AsyncAgentWebSocketClient 7 | 8 | from .response import ( 9 | #### common websocket response 10 | BaseResponse, 11 | OpenResponse, 12 | CloseResponse, 13 | ErrorResponse, 14 | UnhandledResponse, 15 | #### unique 16 | WelcomeResponse, 17 | SettingsAppliedResponse, 18 | ConversationTextResponse, 19 | UserStartedSpeakingResponse, 20 | AgentThinkingResponse, 21 | FunctionCallRequest, 22 | AgentStartedSpeakingResponse, 23 | AgentAudioDoneResponse, 24 | InjectionRefusedResponse, 25 | ) 26 | from .options import ( 27 | # top level 28 | SettingsOptions, 29 | UpdatePromptOptions, 30 | UpdateSpeakOptions, 31 | InjectAgentMessageOptions, 32 | FunctionCallResponse, 33 | AgentKeepAlive, 34 | # sub level 35 | Listen, 36 | ListenProvider, 37 | Speak, 38 | SpeakProvider, 39 | Header, 40 | Item, 41 | Properties, 42 | Parameters, 43 | Function, 44 | Think, 45 | ThinkProvider, 46 | Agent, 47 | Input, 48 | Output, 49 | Audio, 50 | Endpoint, 51 | ) 52 | -------------------------------------------------------------------------------- /deepgram/clients/analyze/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from .client import AnalyzeClient, AsyncAnalyzeClient 6 | from .client import ReadClient, AsyncReadClient 7 | from .client import AnalyzeOptions 8 | from .client import ( 9 | # common 10 | UrlSource, 11 | TextSource, 12 | BufferSource, 13 | StreamSource, 14 | FileSource, 15 | # unique 16 | AnalyzeStreamSource, 17 | AnalyzeSource, 18 | ) 19 | from .client import ( 20 | AsyncAnalyzeResponse, 21 | SyncAnalyzeResponse, 22 | AnalyzeResponse, 23 | # shared 24 | Average, 25 | Intent, 26 | Intents, 27 | IntentsInfo, 28 | Segment, 29 | SentimentInfo, 30 | Sentiment, 31 | Sentiments, 32 | SummaryInfo, 33 | Topic, 34 | Topics, 35 | TopicsInfo, 36 | # unique 37 | AnalyzeMetadata, 38 | AnalyzeResults, 39 | AnalyzeSummary, 40 | ) 41 | -------------------------------------------------------------------------------- /deepgram/clients/analyze/v1/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from .client import AnalyzeClient 6 | from .async_client import AsyncAnalyzeClient 7 | 8 | # common 9 | from .options import ( 10 | UrlSource, 11 | TextSource, 12 | BufferSource, 13 | StreamSource, 14 | FileSource, 15 | ) 16 | 17 | # analyze 18 | 19 | from .options import ( 20 | AnalyzeOptions, 21 | AnalyzeStreamSource, 22 | AnalyzeSource, 23 | ) 24 | 25 | from .response import ( 26 | AsyncAnalyzeResponse, 27 | SyncAnalyzeResponse, 28 | AnalyzeResponse, 29 | # shared 30 | Average, 31 | Intent, 32 | Intents, 33 | IntentsInfo, 34 | Segment, 35 | SentimentInfo, 36 | Sentiment, 37 | Sentiments, 38 | SummaryInfo, 39 | Topic, 40 | Topics, 41 | TopicsInfo, 42 | # unique 43 | Metadata, 44 | Results, 45 | Summary, 46 | ) 47 | -------------------------------------------------------------------------------- /deepgram/clients/analyze/v1/helpers.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from .options import AnalyzeSource 6 | 7 | 8 | def is_buffer_source(provided_source: AnalyzeSource) -> bool: 9 | """ 10 | Check if the provided source is a buffer source. 11 | """ 12 | return "buffer" in provided_source 13 | 14 | 15 | def is_readstream_source(provided_source: AnalyzeSource) -> bool: 16 | """ 17 | Check if the provided source is a readstream source. 18 | """ 19 | return "stream" in provided_source 20 | 21 | 22 | def is_url_source(provided_source: AnalyzeSource) -> bool: 23 | """ 24 | Check if the provided source is a url source. 25 | """ 26 | return "url" in provided_source 27 | -------------------------------------------------------------------------------- /deepgram/clients/auth/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from .client import AuthRESTClient 6 | from .client import AsyncAuthRESTClient 7 | from .client import ( 8 | GrantTokenResponse, 9 | ) -------------------------------------------------------------------------------- /deepgram/clients/auth/client.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from .v1.client import AuthRESTClient as AuthRESTClientLatest 6 | from .v1.async_client import AsyncAuthRESTClient as AsyncAuthRESTClientLatest 7 | from .v1.response import GrantTokenResponse as GrantTokenResponseLatest 8 | 9 | AuthRESTClient = AuthRESTClientLatest 10 | AsyncAuthRESTClient = AsyncAuthRESTClientLatest 11 | GrantTokenResponse = GrantTokenResponseLatest 12 | -------------------------------------------------------------------------------- /deepgram/clients/auth/v1/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | from .client import AuthRESTClient 5 | from .async_client import AsyncAuthRESTClient 6 | from .response import ( 7 | GrantTokenResponse, 8 | ) -------------------------------------------------------------------------------- /deepgram/clients/auth/v1/async_client.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import logging 6 | 7 | from ....utils import verboselogs 8 | from ....options import DeepgramClientOptions 9 | from ...common import AbstractAsyncRestClient 10 | from .response import GrantTokenResponse 11 | 12 | 13 | class AsyncAuthRESTClient(AbstractAsyncRestClient): 14 | """ 15 | A client class for handling authentication endpoints. 16 | Provides method for generating a temporary JWT token. 17 | """ 18 | 19 | _logger: verboselogs.VerboseLogger 20 | _config: DeepgramClientOptions 21 | _endpoint: str 22 | 23 | def __init__(self, config: DeepgramClientOptions): 24 | self._logger = verboselogs.VerboseLogger(__name__) 25 | self._logger.addHandler(logging.StreamHandler()) 26 | self._logger.setLevel(config.verbose) 27 | self._config = config 28 | self._endpoint = "v1/auth/grant" 29 | super().__init__(config) 30 | 31 | async def grant_token(self): 32 | """ 33 | Generates a temporary JWT with a 30 second TTL. 34 | 35 | Returns: 36 | GrantTokenResponse: An object containing the authentication token and its expiration time. 37 | 38 | Raises: 39 | DeepgramTypeError: Raised for known API errors. 40 | """ 41 | self._logger.debug("AuthRestClient.grant_token ENTER") 42 | 43 | url = f"{self._config.url}/{self._endpoint}" 44 | self._logger.info("url: %s", url) 45 | result = await self.post(url, headers={"Authorization": f"Token {self._config.api_key}"}) 46 | self._logger.info("json: %s", result) 47 | res = GrantTokenResponse.from_json(result) 48 | self._logger.verbose("result: %s", res) 49 | self._logger.notice("grant_token succeeded") 50 | self._logger.debug("AuthRestClient.grant_token LEAVE") 51 | return res 52 | -------------------------------------------------------------------------------- /deepgram/clients/auth/v1/client.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import logging 6 | 7 | from ....utils import verboselogs 8 | from ....options import DeepgramClientOptions 9 | from ...common import AbstractSyncRestClient 10 | from .response import GrantTokenResponse 11 | 12 | 13 | class AuthRESTClient(AbstractSyncRestClient): 14 | """ 15 | A client class for handling authentication endpoints. 16 | Provides method for generating a temporary JWT token. 17 | """ 18 | 19 | _logger: verboselogs.VerboseLogger 20 | _config: DeepgramClientOptions 21 | _endpoint: str 22 | 23 | def __init__(self, config: DeepgramClientOptions): 24 | self._logger = verboselogs.VerboseLogger(__name__) 25 | self._logger.addHandler(logging.StreamHandler()) 26 | self._logger.setLevel(config.verbose) 27 | self._config = config 28 | self._endpoint = "v1/auth/grant" 29 | super().__init__(config) 30 | 31 | def grant_token(self): 32 | """ 33 | Generates a temporary JWT with a 30 second TTL. 34 | 35 | Returns: 36 | GrantTokenResponse: An object containing the authentication token and its expiration time. 37 | 38 | Raises: 39 | DeepgramTypeError: Raised for known API errors. 40 | """ 41 | self._logger.debug("AuthRestClient.grant_token ENTER") 42 | 43 | url = f"{self._config.url}/{self._endpoint}" 44 | self._logger.info("url: %s", url) 45 | result = self.post(url, headers={"Authorization": f"Token {self._config.api_key}"}) 46 | self._logger.info("json: %s", result) 47 | res = GrantTokenResponse.from_json(result) 48 | self._logger.verbose("result: %s", res) 49 | self._logger.notice("grant_token succeeded") 50 | self._logger.debug("AuthRestClient.grant_token LEAVE") 51 | return res 52 | -------------------------------------------------------------------------------- /deepgram/clients/auth/v1/response.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from dataclasses import dataclass, field 6 | from dataclasses_json import config as dataclass_config 7 | 8 | from ...common import ( 9 | BaseResponse, 10 | ) 11 | 12 | @dataclass 13 | class GrantTokenResponse(BaseResponse): 14 | """ 15 | The response object for the authentication grant token endpoint. 16 | """ 17 | access_token: str = field( 18 | metadata=dataclass_config(field_name='access_token'), 19 | default="", 20 | ) 21 | expires_in: int = field( 22 | metadata=dataclass_config(field_name='expires_in'), 23 | default=30, 24 | ) -------------------------------------------------------------------------------- /deepgram/clients/common/v1/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from .enums import Sentiment 6 | 7 | from .errors import ( 8 | DeepgramError, 9 | DeepgramTypeError, 10 | DeepgramApiError, 11 | DeepgramUnknownApiError, 12 | ) 13 | from .abstract_async_rest import AbstractAsyncRestClient 14 | from .abstract_sync_rest import AbstractSyncRestClient 15 | from .abstract_async_websocket import AbstractAsyncWebSocketClient 16 | from .abstract_sync_websocket import AbstractSyncWebSocketClient 17 | 18 | from .options import ( 19 | TextSource, 20 | BufferSource, 21 | StreamSource, 22 | FileSource, 23 | UrlSource, 24 | ) 25 | 26 | from .shared_response import ( 27 | BaseResponse, 28 | ModelInfo, 29 | Hit, 30 | Search, 31 | ) 32 | 33 | from .rest_response import ( 34 | Average, 35 | Intent, 36 | Intents, 37 | IntentsInfo, 38 | Segment, 39 | SentimentInfo, 40 | Sentiment, 41 | Sentiments, 42 | SummaryInfo, 43 | Topic, 44 | Topics, 45 | TopicsInfo, 46 | ) 47 | 48 | from .websocket_response import ( 49 | OpenResponse, 50 | CloseResponse, 51 | ErrorResponse, 52 | UnhandledResponse, 53 | ) 54 | -------------------------------------------------------------------------------- /deepgram/clients/common/v1/enums.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from aenum import StrEnum 6 | 7 | # Constants mapping to events from the Deepgram API 8 | 9 | 10 | class Sentiment(StrEnum): 11 | """ 12 | Sentiment values. 13 | """ 14 | 15 | UNKNOWN: str = "" 16 | NEGATIVE: str = "negative" 17 | NEUTRAL: str = "neutral" 18 | POSITIVE: str = "positive" 19 | -------------------------------------------------------------------------------- /deepgram/clients/common/v1/helpers.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from urllib.parse import urlparse, urlunparse, parse_qs, urlencode 6 | from typing import Dict, Optional 7 | import re 8 | 9 | 10 | # This function appends query parameters to a URL 11 | def append_query_params(url: str, params: Optional[Dict] = None): 12 | """ 13 | Appends query parameters to a URL 14 | """ 15 | parsed_url = urlparse(url) 16 | query_params = parse_qs(parsed_url.query) 17 | 18 | if params is not None: 19 | for key, value in params.items(): 20 | if value is None: 21 | continue 22 | if isinstance(value, bool): 23 | value = str(value).lower() 24 | if isinstance(value, list): 25 | for item in value: 26 | query_params[key] = query_params.get(key, []) + [str(item)] 27 | else: 28 | query_params[key] = [str(value)] 29 | 30 | updated_query_string = urlencode(query_params, doseq=True) 31 | updated_url = parsed_url._replace(query=updated_query_string).geturl() 32 | return updated_url 33 | 34 | 35 | # This function converts a URL to a WebSocket URL 36 | def convert_to_websocket_url(base_url: str, endpoint: str): 37 | """ 38 | Converts a URL to a WebSocket URL 39 | """ 40 | use_ssl = True # Default to true 41 | if re.match(r"^https?://", base_url, re.IGNORECASE): 42 | if "http://" in base_url: 43 | use_ssl = False # Override to false if http:// is found 44 | base_url = base_url.replace("https://", "").replace("http://", "") 45 | if not re.match(r"^wss?://", base_url, re.IGNORECASE): 46 | if use_ssl: 47 | base_url = "wss://" + base_url 48 | else: 49 | base_url = "ws://" + base_url 50 | parsed_url = urlparse(base_url) 51 | domain = parsed_url.netloc 52 | websocket_url = urlunparse((parsed_url.scheme, domain, endpoint, "", "", "")) 53 | return websocket_url 54 | -------------------------------------------------------------------------------- /deepgram/clients/common/v1/options.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from io import BufferedReader 6 | from typing import Union 7 | from typing_extensions import TypedDict 8 | 9 | 10 | class StreamSource(TypedDict): 11 | """ 12 | Represents a data source for reading binary data from a stream-like source. 13 | 14 | This class is used to specify a source of binary data that can be read from 15 | a stream, such as an audio file in .wav format. 16 | 17 | Attributes: 18 | stream (BufferedReader): A BufferedReader object for reading binary data. 19 | """ 20 | 21 | stream: BufferedReader 22 | 23 | 24 | class UrlSource(TypedDict): 25 | """ 26 | Represents a data source for specifying the location of a file via a URL. 27 | 28 | This class is used to specify a hosted file URL, typically pointing to an 29 | externally hosted file, such as an audio file hosted on a server or the internet. 30 | 31 | Attributes: 32 | url (str): The URL pointing to the hosted file. 33 | """ 34 | 35 | url: str 36 | 37 | 38 | class BufferSource(TypedDict): 39 | """ 40 | Represents a data source for handling raw binary data. 41 | 42 | This class is used to specify raw binary data, such as audio data in its 43 | binary form, which can be captured from a microphone or generated synthetically. 44 | 45 | Attributes: 46 | buffer (bytes): The binary data. 47 | """ 48 | 49 | buffer: bytes 50 | 51 | 52 | class TextSource(TypedDict): 53 | """ 54 | Represents a data source for reading binary data from a text-like source. 55 | 56 | This class is used to specify a source of text data that can be read from. 57 | 58 | Attributes: 59 | text (str): A string for reading text data. 60 | """ 61 | 62 | text: str 63 | 64 | 65 | FileSource = Union[TextSource, BufferSource, StreamSource] 66 | -------------------------------------------------------------------------------- /deepgram/clients/common/v1/shared_response.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from typing import List, Optional, Dict, Any 6 | 7 | 8 | from dataclasses import dataclass, field 9 | from dataclasses_json import config as dataclass_config, DataClassJsonMixin 10 | 11 | 12 | # base class 13 | 14 | 15 | @dataclass 16 | class BaseResponse(DataClassJsonMixin): 17 | """ 18 | BaseResponse class used to define the common methods and properties for all response classes. 19 | """ 20 | 21 | def __getitem__(self, key): 22 | _dict = self.to_dict() 23 | return _dict[key] 24 | 25 | def __setitem__(self, key, val): 26 | self.__dict__[key] = val 27 | 28 | def __str__(self) -> str: 29 | return self.to_json(indent=4) 30 | 31 | def eval(self, key: str) -> str: 32 | """ 33 | This method is used to evaluate a key in the response object using a dot notation style method. 34 | """ 35 | keys = key.split(".") 36 | result: Dict[Any, Any] = self.to_dict() 37 | for k in keys: 38 | if isinstance(result, dict) and k in result: 39 | result = result[k] 40 | elif isinstance(result, list) and k.isdigit() and int(k) < len(result): 41 | result = result[int(k)] 42 | else: 43 | return "" 44 | return str(result) 45 | 46 | 47 | # shared classes 48 | 49 | 50 | @dataclass 51 | class ModelInfo(BaseResponse): 52 | """ 53 | ModelInfo object 54 | """ 55 | 56 | name: str = "" 57 | version: str = "" 58 | arch: str = "" 59 | 60 | 61 | @dataclass 62 | class Hit(BaseResponse): 63 | """ 64 | The hit information for the response. 65 | """ 66 | 67 | confidence: float = 0 68 | start: float = 0 69 | end: float = 0 70 | snippet: Optional[str] = "" 71 | 72 | 73 | @dataclass 74 | class Search(BaseResponse): 75 | """ 76 | The search information for the response. 77 | """ 78 | 79 | query: str = "" 80 | hits: List[Hit] = field(default_factory=list) 81 | 82 | def __getitem__(self, key): 83 | _dict = self.to_dict() 84 | if "hits" in _dict: 85 | _dict["hits"] = [Hit.from_dict(hits) for hits in _dict["hits"]] 86 | return _dict[key] 87 | -------------------------------------------------------------------------------- /deepgram/clients/common/v1/websocket_events.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from aenum import StrEnum 6 | 7 | # Constants mapping to events from the Deepgram API 8 | 9 | 10 | class WebSocketEvents(StrEnum): 11 | """ 12 | Enumerates the possible events that can be received from the Deepgram API 13 | """ 14 | 15 | Open: str = "Open" 16 | Close: str = "Close" 17 | Warning: str = "Warning" 18 | Error: str = "Error" 19 | Unhandled: str = "Unhandled" 20 | -------------------------------------------------------------------------------- /deepgram/clients/common/v1/websocket_response.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from typing import List, Optional, Dict, Any 6 | 7 | from dataclasses import dataclass, field 8 | from dataclasses_json import config as dataclass_config 9 | 10 | from .shared_response import BaseResponse 11 | 12 | 13 | # Result Message 14 | 15 | 16 | @dataclass 17 | class OpenResponse(BaseResponse): 18 | """ 19 | Open Message from the Deepgram Platform 20 | """ 21 | 22 | type: str = "" 23 | 24 | 25 | # Close Message 26 | 27 | 28 | @dataclass 29 | class CloseResponse(BaseResponse): 30 | """ 31 | Close Message from the Deepgram Platform 32 | """ 33 | 34 | type: str = "" 35 | 36 | 37 | # Error Message 38 | 39 | 40 | @dataclass 41 | class ErrorResponse(BaseResponse): 42 | """ 43 | Error Message from the Deepgram Platform 44 | """ 45 | 46 | description: str = "" 47 | message: str = "" 48 | type: str = "" 49 | variant: Optional[str] = field( 50 | default=None, metadata=dataclass_config(exclude=lambda f: f is None) 51 | ) 52 | 53 | 54 | # Unhandled Message 55 | 56 | 57 | @dataclass 58 | class UnhandledResponse(BaseResponse): 59 | """ 60 | Unhandled Message from the Deepgram Platform 61 | """ 62 | 63 | type: str = "" 64 | raw: str = "" 65 | -------------------------------------------------------------------------------- /deepgram/clients/errors.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | 6 | class DeepgramModuleError(Exception): 7 | """ 8 | Base class for exceptions raised for a missing Deepgram module. 9 | 10 | Attributes: 11 | message (str): The error message describing the exception. 12 | """ 13 | 14 | def __init__(self, message: str): 15 | super().__init__(message) 16 | self.name = "DeepgramModuleError" 17 | -------------------------------------------------------------------------------- /deepgram/clients/listen/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from .enums import LiveTranscriptionEvents 6 | 7 | # backward compat 8 | from .client import ( 9 | PreRecordedClient, 10 | AsyncPreRecordedClient, 11 | LiveClient, 12 | AsyncLiveClient, 13 | ) 14 | 15 | # rest 16 | # common 17 | from .client import ( 18 | UrlSource, 19 | TextSource, 20 | BufferSource, 21 | StreamSource, 22 | FileSource, 23 | ) 24 | 25 | ## input 26 | from .client import ( 27 | ListenRESTOptions, 28 | PrerecordedOptions, 29 | PreRecordedStreamSource, 30 | PrerecordedSource, 31 | ListenRestSource, 32 | ) 33 | 34 | ## output 35 | from .client import ( 36 | # top level 37 | AsyncPrerecordedResponse, 38 | PrerecordedResponse, 39 | SyncPrerecordedResponse, 40 | # shared 41 | Average, 42 | Intent, 43 | Intents, 44 | IntentsInfo, 45 | Segment, 46 | SentimentInfo, 47 | Sentiment, 48 | Sentiments, 49 | SummaryInfo, 50 | Topic, 51 | Topics, 52 | TopicsInfo, 53 | # between rest and websocket 54 | ModelInfo, 55 | Hit, 56 | Search, 57 | # unique 58 | Entity, 59 | ListenRESTMetadata, 60 | Paragraph, 61 | Paragraphs, 62 | ListenRESTResults, 63 | Sentence, 64 | Summaries, 65 | SummaryV1, 66 | SummaryV2, 67 | Translation, 68 | Utterance, 69 | Warning, 70 | ListenRESTAlternative, 71 | ListenRESTChannel, 72 | ListenRESTWord, 73 | ) 74 | 75 | 76 | # websocket 77 | ## input 78 | from .client import ( 79 | ListenWebSocketOptions, 80 | LiveOptions, 81 | ) 82 | 83 | ## output 84 | from .client import ( 85 | # top level 86 | LiveResultResponse, 87 | ListenWSMetadataResponse, 88 | SpeechStartedResponse, 89 | UtteranceEndResponse, 90 | # common websocket response 91 | OpenResponse, 92 | CloseResponse, 93 | ErrorResponse, 94 | UnhandledResponse, 95 | # unique 96 | ListenWSMetadata, 97 | ListenWSWord, 98 | ListenWSAlternative, 99 | ListenWSChannel, 100 | ) 101 | 102 | # clients 103 | from .client import ( 104 | ListenRESTClient, 105 | AsyncListenRESTClient, 106 | ListenWebSocketClient, 107 | AsyncListenWebSocketClient, 108 | ) 109 | -------------------------------------------------------------------------------- /deepgram/clients/listen/enums.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from aenum import StrEnum 6 | 7 | # Constants mapping to events from the Deepgram API 8 | 9 | 10 | class LiveTranscriptionEvents(StrEnum): 11 | """ 12 | Enumerates the possible events that can be received from the Deepgram API 13 | """ 14 | 15 | Open: str = "Open" 16 | Close: str = "Close" 17 | Transcript: str = "Results" 18 | Metadata: str = "Metadata" 19 | UtteranceEnd: str = "UtteranceEnd" 20 | SpeechStarted: str = "SpeechStarted" 21 | Finalize: str = "Finalize" 22 | Error: str = "Error" 23 | Unhandled: str = "Unhandled" 24 | Warning: str = "Warning" 25 | -------------------------------------------------------------------------------- /deepgram/clients/listen/v1/rest/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from .client import ListenRESTClient 6 | from .async_client import AsyncListenRESTClient 7 | from .options import ( 8 | ListenRESTOptions, 9 | PrerecordedOptions, 10 | # common 11 | UrlSource, 12 | BufferSource, 13 | StreamSource, 14 | TextSource, 15 | FileSource, 16 | # unique 17 | PreRecordedStreamSource, 18 | PrerecordedSource, 19 | ListenRestSource, 20 | ) 21 | from .response import ( 22 | # top level 23 | AsyncPrerecordedResponse, 24 | PrerecordedResponse, 25 | SyncPrerecordedResponse, 26 | # shared 27 | Average, 28 | Intent, 29 | Intents, 30 | IntentsInfo, 31 | Segment, 32 | SentimentInfo, 33 | Sentiment, 34 | Sentiments, 35 | SummaryInfo, 36 | Topic, 37 | Topics, 38 | TopicsInfo, 39 | # between rest and websocket 40 | ModelInfo, 41 | Hit, 42 | Search, 43 | # unique 44 | Entity, 45 | Metadata, 46 | Paragraph, 47 | Paragraphs, 48 | Results, 49 | Sentence, 50 | Summaries, 51 | SummaryV1, 52 | SummaryV2, 53 | Translation, 54 | Utterance, 55 | Warning, 56 | ListenRESTAlternative, 57 | ListenRESTChannel, 58 | ListenRESTWord, 59 | ) 60 | -------------------------------------------------------------------------------- /deepgram/clients/listen/v1/rest/helpers.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from .options import PrerecordedSource 6 | 7 | 8 | def is_buffer_source(provided_source: PrerecordedSource) -> bool: 9 | """ 10 | Check if the provided source is a buffer source. 11 | """ 12 | return "buffer" in provided_source 13 | 14 | 15 | def is_readstream_source(provided_source: PrerecordedSource) -> bool: 16 | """ 17 | Check if the provided source is a readstream source. 18 | """ 19 | return "stream" in provided_source 20 | 21 | 22 | def is_url_source(provided_source: PrerecordedSource) -> bool: 23 | """ 24 | Check if the provided source is a URL source. 25 | """ 26 | return "url" in provided_source 27 | -------------------------------------------------------------------------------- /deepgram/clients/listen/v1/websocket/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from .client import ListenWebSocketClient 6 | from .async_client import AsyncListenWebSocketClient 7 | from .options import LiveOptions, ListenWebSocketOptions 8 | 9 | # unique websocket response 10 | from .response import ( 11 | #### top level 12 | LiveResultResponse, 13 | MetadataResponse, 14 | SpeechStartedResponse, 15 | UtteranceEndResponse, 16 | #### common websocket response 17 | BaseResponse, 18 | OpenResponse, 19 | CloseResponse, 20 | ErrorResponse, 21 | UnhandledResponse, 22 | #### between rest and websocket 23 | ModelInfo, 24 | Hit, 25 | Search, 26 | #### unique 27 | Metadata, 28 | ListenWSWord, 29 | ListenWSAlternative, 30 | ListenWSChannel, 31 | ) 32 | -------------------------------------------------------------------------------- /deepgram/clients/live/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from .v1 import LiveTranscriptionEvents 6 | 7 | from .v1 import LiveClient 8 | from .v1 import AsyncLiveClient 9 | from .v1 import LiveOptions 10 | from .v1 import ( 11 | OpenResponse, 12 | LiveResultResponse, 13 | ListenWSMetadataResponse, 14 | MetadataResponse, # backwards compat 15 | SpeechStartedResponse, 16 | UtteranceEndResponse, 17 | CloseResponse, 18 | ErrorResponse, 19 | UnhandledResponse, 20 | ) 21 | -------------------------------------------------------------------------------- /deepgram/clients/live/v1/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from .enums import LiveTranscriptionEvents 6 | 7 | from .client import LiveClient 8 | from .client import AsyncLiveClient 9 | from .client import LiveOptions 10 | from .client import ( 11 | OpenResponse, 12 | LiveResultResponse, 13 | ListenWSMetadataResponse, 14 | MetadataResponse, # backwards compat 15 | SpeechStartedResponse, 16 | UtteranceEndResponse, 17 | CloseResponse, 18 | ErrorResponse, 19 | UnhandledResponse, 20 | ) 21 | -------------------------------------------------------------------------------- /deepgram/clients/live/v1/client.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from ...listen.v1 import ListenWebSocketClient as LiveClientLatest 6 | from ...listen.v1 import AsyncListenWebSocketClient as AsyncLiveClientLatest 7 | from ...listen.v1 import LiveOptions as LiveOptionsLatest 8 | from ...listen.v1 import ( 9 | OpenResponse as OpenResponseLatest, 10 | LiveResultResponse as LiveResultResponseLatest, 11 | ListenWSMetadataResponse as ListenWSMetadataResponseLatest, 12 | SpeechStartedResponse as SpeechStartedResponseLatest, 13 | UtteranceEndResponse as UtteranceEndResponseLatest, 14 | CloseResponse as CloseResponseLatest, 15 | ErrorResponse as ErrorResponseLatest, 16 | UnhandledResponse as UnhandledResponseLatest, 17 | ) 18 | 19 | # The vX/client.py points to the current supported version in the SDK. 20 | # Older versions are supported in the SDK for backwards compatibility. 21 | 22 | 23 | # input 24 | LiveOptions = LiveOptionsLatest 25 | OpenResponse = OpenResponseLatest 26 | LiveResultResponse = LiveResultResponseLatest 27 | ListenWSMetadataResponse = ListenWSMetadataResponseLatest 28 | MetadataResponse = ListenWSMetadataResponseLatest 29 | SpeechStartedResponse = SpeechStartedResponseLatest 30 | UtteranceEndResponse = UtteranceEndResponseLatest 31 | CloseResponse = CloseResponseLatest 32 | ErrorResponse = ErrorResponseLatest 33 | UnhandledResponse = UnhandledResponseLatest 34 | 35 | 36 | # clients 37 | LiveClient = LiveClientLatest 38 | AsyncLiveClient = AsyncLiveClientLatest 39 | -------------------------------------------------------------------------------- /deepgram/clients/live/v1/enums.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from ...listen import LiveTranscriptionEvents 6 | -------------------------------------------------------------------------------- /deepgram/clients/manage/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from .client import ManageClient 6 | from .client import AsyncManageClient 7 | from .client import ( 8 | ProjectOptions, 9 | KeyOptions, 10 | ScopeOptions, 11 | InviteOptions, 12 | UsageRequestOptions, 13 | UsageSummaryOptions, 14 | UsageFieldsOptions, 15 | ) 16 | from .client import ( 17 | #### top level 18 | Message, 19 | ProjectsResponse, 20 | ModelResponse, 21 | ModelsResponse, 22 | MembersResponse, 23 | KeyResponse, 24 | KeysResponse, 25 | ScopesResponse, 26 | InvitesResponse, 27 | UsageRequest, 28 | UsageResponse, 29 | UsageRequestsResponse, 30 | UsageSummaryResponse, 31 | UsageFieldsResponse, 32 | BalancesResponse, 33 | #### shared 34 | Project, 35 | STTDetails, 36 | TTSMetadata, 37 | TTSDetails, 38 | Member, 39 | Key, 40 | Invite, 41 | Config, 42 | STTUsageDetails, 43 | Callback, 44 | TokenDetail, 45 | SpeechSegment, 46 | TTSUsageDetails, 47 | STTTokens, 48 | TTSTokens, 49 | UsageSummaryResults, 50 | Resolution, 51 | UsageModel, 52 | Balance, 53 | ) 54 | -------------------------------------------------------------------------------- /deepgram/clients/manage/v1/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from .client import ManageClient 6 | from .async_client import AsyncManageClient 7 | from .options import ( 8 | ProjectOptions, 9 | KeyOptions, 10 | ScopeOptions, 11 | InviteOptions, 12 | UsageRequestOptions, 13 | UsageSummaryOptions, 14 | UsageFieldsOptions, 15 | ) 16 | 17 | from .response import ( 18 | #### top level 19 | Message, 20 | ProjectsResponse, 21 | ModelResponse, 22 | ModelsResponse, 23 | MembersResponse, 24 | KeyResponse, 25 | KeysResponse, 26 | ScopesResponse, 27 | InvitesResponse, 28 | UsageRequest, 29 | UsageResponse, 30 | UsageRequestsResponse, 31 | UsageSummaryResponse, 32 | UsageFieldsResponse, 33 | BalancesResponse, 34 | #### shared 35 | Project, 36 | STTDetails, 37 | TTSMetadata, 38 | TTSDetails, 39 | Member, 40 | Key, 41 | Invite, 42 | Config, 43 | STTUsageDetails, 44 | Callback, 45 | TokenDetail, 46 | SpeechSegment, 47 | TTSUsageDetails, 48 | STTTokens, 49 | TTSTokens, 50 | UsageSummaryResults, 51 | Resolution, 52 | UsageModel, 53 | Balance, 54 | ) 55 | -------------------------------------------------------------------------------- /deepgram/clients/prerecorded/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from .v1 import PreRecordedClient 6 | from .v1 import AsyncPreRecordedClient 7 | from .v1 import PrerecordedOptions 8 | from .v1 import ( 9 | UrlSource, 10 | FileSource, 11 | PreRecordedStreamSource, 12 | PrerecordedSource, 13 | ) 14 | from .v1 import ( 15 | AsyncPrerecordedResponse, 16 | PrerecordedResponse, 17 | SyncPrerecordedResponse, 18 | ) 19 | -------------------------------------------------------------------------------- /deepgram/clients/prerecorded/v1/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from .client import PreRecordedClient 6 | from .client import AsyncPreRecordedClient 7 | from .client import PrerecordedOptions 8 | from .client import ( 9 | UrlSource, 10 | FileSource, 11 | PreRecordedStreamSource, 12 | PrerecordedSource, 13 | ) 14 | from .client import ( 15 | AsyncPrerecordedResponse, 16 | PrerecordedResponse, 17 | SyncPrerecordedResponse, 18 | ) 19 | -------------------------------------------------------------------------------- /deepgram/clients/prerecorded/v1/client.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from ...listen import PreRecordedClient as PreRecordedClientLatest 6 | from ...listen import AsyncPreRecordedClient as AsyncPreRecordedClientLatest 7 | from ...listen import ( 8 | PrerecordedOptions as PrerecordedOptionsLatest, 9 | UrlSource as UrlSourceLatest, 10 | FileSource as FileSourceLatest, 11 | PreRecordedStreamSource as PreRecordedStreamSourceLatest, 12 | PrerecordedSource as PrerecordedSourceLatest, 13 | ) 14 | from ...listen import ( 15 | AsyncPrerecordedResponse as AsyncPrerecordedResponseLatest, 16 | PrerecordedResponse as PrerecordedResponseLatest, 17 | SyncPrerecordedResponse as SyncPrerecordedResponseLatest, 18 | ) 19 | 20 | 21 | # input 22 | PrerecordedOptions = PrerecordedOptionsLatest 23 | PreRecordedStreamSource = PreRecordedStreamSourceLatest 24 | UrlSource = UrlSourceLatest 25 | FileSource = FileSourceLatest 26 | PrerecordedSource = PrerecordedSourceLatest 27 | 28 | 29 | # output 30 | AsyncPrerecordedResponse = AsyncPrerecordedResponseLatest 31 | PrerecordedResponse = PrerecordedResponseLatest 32 | SyncPrerecordedResponse = SyncPrerecordedResponseLatest 33 | 34 | 35 | # clients 36 | PreRecordedClient = PreRecordedClientLatest 37 | AsyncPreRecordedClient = AsyncPreRecordedClientLatest 38 | -------------------------------------------------------------------------------- /deepgram/clients/prerecorded/v1/errors.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | 6 | class DeepgramError(Exception): 7 | """ 8 | Exception raised for unknown errors related to the Deepgram API. 9 | 10 | Attributes: 11 | message (str): The error message describing the exception. 12 | """ 13 | 14 | def __init__(self, message: str): 15 | super().__init__(message) 16 | self.name = "DeepgramError" 17 | self.message = message 18 | 19 | def __str__(self): 20 | return f"{self.name}: {self.message}" 21 | 22 | 23 | class DeepgramTypeError(Exception): 24 | """ 25 | Exception raised for unknown errors related to unknown Types for Transcription. 26 | 27 | Attributes: 28 | message (str): The error message describing the exception. 29 | """ 30 | 31 | def __init__(self, message: str): 32 | super().__init__(message) 33 | self.name = "DeepgramTypeError" 34 | self.message = message 35 | 36 | def __str__(self): 37 | return f"{self.name}: {self.message}" 38 | -------------------------------------------------------------------------------- /deepgram/clients/selfhosted/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from .client import SelfHostedClient, OnPremClient 6 | from .client import AsyncSelfHostedClient, AsyncOnPremClient 7 | -------------------------------------------------------------------------------- /deepgram/clients/selfhosted/client.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from .v1.client import SelfHostedClient as SelfHostedClientLatest 6 | from .v1.async_client import AsyncSelfHostedClient as AsyncSelfHostedClientLatest 7 | 8 | 9 | # The client.py points to the current supported version in the SDK. 10 | # Older versions are supported in the SDK for backwards compatibility. 11 | 12 | SelfHostedClient = SelfHostedClientLatest 13 | AsyncSelfHostedClient = AsyncSelfHostedClientLatest 14 | OnPremClient = SelfHostedClientLatest 15 | AsyncOnPremClient = AsyncSelfHostedClientLatest 16 | -------------------------------------------------------------------------------- /deepgram/clients/selfhosted/v1/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from .client import SelfHostedClient 6 | from .async_client import AsyncSelfHostedClient 7 | -------------------------------------------------------------------------------- /deepgram/clients/speak/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from .enums import SpeakWebSocketEvents, SpeakWebSocketMessage 6 | 7 | # rest 8 | from .client import ( 9 | SpeakClient, # backward compat 10 | SpeakRESTClient, 11 | AsyncSpeakRESTClient, 12 | ) 13 | from .client import ( 14 | #### top level 15 | SpeakRESTOptions, 16 | SpeakOptions, 17 | # common 18 | TextSource, 19 | BufferSource, 20 | StreamSource, 21 | FileSource, 22 | # unique 23 | SpeakSource, 24 | SpeakRestSource, 25 | SpeakRESTSource, 26 | ) 27 | from .client import ( 28 | SpeakResponse, # backward compat 29 | SpeakRESTResponse, 30 | ) 31 | 32 | # websocket 33 | from .client import ( 34 | SpeakWSOptions, 35 | ) 36 | from .client import ( 37 | SpeakWebSocketClient, 38 | AsyncSpeakWebSocketClient, 39 | SpeakWSClient, 40 | AsyncSpeakWSClient, 41 | ) 42 | from .client import ( 43 | #### top level 44 | SpeakWSMetadataResponse, 45 | FlushedResponse, 46 | ClearedResponse, 47 | WarningResponse, 48 | #### shared 49 | OpenResponse, 50 | CloseResponse, 51 | UnhandledResponse, 52 | ErrorResponse, 53 | ) 54 | -------------------------------------------------------------------------------- /deepgram/clients/speak/enums.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from aenum import StrEnum 6 | 7 | # Constants mapping to events from the Deepgram API 8 | 9 | 10 | class SpeakWebSocketMessage(StrEnum): 11 | """ 12 | Enumerates the possible message types that can be received from the Deepgram API 13 | """ 14 | 15 | Speak: str = "Speak" 16 | Flush: str = "Flush" 17 | Clear: str = "Clear" 18 | Close: str = "Close" 19 | 20 | 21 | class SpeakWebSocketEvents(StrEnum): 22 | """ 23 | Enumerates the possible events that can be received from the Deepgram API 24 | """ 25 | 26 | Open: str = "Open" 27 | Close: str = "Close" 28 | AudioData: str = "AudioData" 29 | Metadata: str = "Metadata" 30 | Flushed: str = "Flushed" 31 | Cleared: str = "Cleared" 32 | Unhandled: str = "Unhandled" 33 | Error: str = "Error" 34 | Warning: str = "Warning" 35 | -------------------------------------------------------------------------------- /deepgram/clients/speak/v1/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | # rest 6 | from .rest import ( 7 | #### top level 8 | SpeakRESTOptions, 9 | SpeakOptions, 10 | # common 11 | TextSource, 12 | BufferSource, 13 | StreamSource, 14 | FileSource, 15 | # unique 16 | SpeakSource, 17 | SpeakRestSource, 18 | SpeakRESTSource, 19 | ) 20 | from .rest import ( 21 | SpeakRESTOptions, 22 | SpeakOptions, 23 | ) 24 | from .rest import SpeakRESTClient, AsyncSpeakRESTClient 25 | from .rest import SpeakRESTResponse 26 | 27 | # websocket 28 | from .websocket import ( 29 | SpeakWSOptions, 30 | ) 31 | from .websocket import ( 32 | SpeakWebSocketClient, 33 | AsyncSpeakWebSocketClient, 34 | SpeakWSClient, 35 | AsyncSpeakWSClient, 36 | ) 37 | from .websocket import ( 38 | #### top level 39 | MetadataResponse as SpeakWSMetadataResponse, 40 | FlushedResponse, 41 | ClearedResponse, 42 | WarningResponse, 43 | #### shared 44 | OpenResponse, 45 | CloseResponse, 46 | UnhandledResponse, 47 | ErrorResponse, 48 | ) 49 | -------------------------------------------------------------------------------- /deepgram/clients/speak/v1/rest/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from .client import SpeakRESTClient 6 | from .async_client import AsyncSpeakRESTClient 7 | from .response import SpeakRESTResponse 8 | from .options import ( 9 | #### top level 10 | SpeakRESTOptions, 11 | SpeakOptions, 12 | # common 13 | TextSource, 14 | BufferSource, 15 | StreamSource, 16 | FileSource, 17 | # unique 18 | SpeakSource, 19 | SpeakRestSource, 20 | SpeakRESTSource, 21 | ) 22 | -------------------------------------------------------------------------------- /deepgram/clients/speak/v1/rest/helpers.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from .options import SpeakSource 6 | 7 | 8 | def is_text_source(provided_source: SpeakSource) -> bool: 9 | """ 10 | Check if the provided source is a text source. 11 | """ 12 | return "text" in provided_source 13 | 14 | 15 | def is_readstream_source(provided_source: SpeakSource) -> bool: 16 | """ 17 | Check if the provided source is a readstream source. 18 | """ 19 | return "stream" in provided_source 20 | -------------------------------------------------------------------------------- /deepgram/clients/speak/v1/rest/options.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from io import BufferedReader 6 | from typing import Union, Optional 7 | import logging 8 | 9 | from dataclasses import dataclass, field 10 | from dataclasses_json import config as dataclass_config 11 | 12 | from .....utils import verboselogs 13 | from ....common import TextSource, BufferSource, StreamSource, FileSource, BaseResponse 14 | 15 | 16 | @dataclass 17 | class SpeakRESTOptions(BaseResponse): 18 | """ 19 | Contains all the options for the SpeakOptions. 20 | 21 | Reference: 22 | https://developers.deepgram.com/reference/text-to-speech-api 23 | """ 24 | 25 | model: Optional[str] = field( 26 | default="aura-2-thalia-en", 27 | metadata=dataclass_config(exclude=lambda f: f is None), 28 | ) 29 | encoding: Optional[str] = field( 30 | default=None, metadata=dataclass_config(exclude=lambda f: f is None) 31 | ) 32 | container: Optional[str] = field( 33 | default=None, metadata=dataclass_config(exclude=lambda f: f is None) 34 | ) 35 | sample_rate: Optional[int] = field( 36 | default=None, metadata=dataclass_config(exclude=lambda f: f is None) 37 | ) 38 | bit_rate: Optional[int] = field( 39 | default=None, metadata=dataclass_config(exclude=lambda f: f is None) 40 | ) 41 | 42 | def check(self): 43 | """ 44 | Check the SpeakOptions for any missing or invalid values. 45 | """ 46 | logger = verboselogs.VerboseLogger(__name__) 47 | logger.addHandler(logging.StreamHandler()) 48 | prev = logger.level 49 | logger.setLevel(verboselogs.ERROR) 50 | 51 | # no op at the moment 52 | 53 | logger.setLevel(prev) 54 | 55 | return True 56 | 57 | 58 | SpeakOptions = SpeakRESTOptions 59 | 60 | 61 | # unqiue 62 | SpeakSource = Union[FileSource, BufferedReader] 63 | SpeakRestSource = SpeakSource 64 | SpeakRESTSource = SpeakSource # pylint: disable=invalid-name 65 | -------------------------------------------------------------------------------- /deepgram/clients/speak/v1/rest/response.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from typing import Optional, Dict, Any 6 | import io 7 | 8 | from dataclasses import dataclass, field 9 | from dataclasses_json import config as dataclass_config 10 | 11 | from ....common import ( 12 | BaseResponse, 13 | ) 14 | 15 | 16 | # Speak Response Types: 17 | 18 | 19 | @dataclass 20 | class SpeakRESTResponse(BaseResponse): # pylint: disable=too-many-instance-attributes 21 | """ 22 | A class for representing a response from the speak endpoint. 23 | """ 24 | 25 | content_type: str = "" 26 | request_id: str = "" 27 | model_uuid: str = "" 28 | model_name: str = "" 29 | characters: int = 0 30 | transfer_encoding: str = "" 31 | date: str = "" 32 | filename: Optional[str] = field( 33 | default=None, metadata=dataclass_config(exclude=lambda f: f is None) 34 | ) 35 | # pylint: disable=W0511 36 | # TODO: stream will be deprecated in a future release. Please use stream_memory instead. 37 | stream: Optional[io.BytesIO] = field( 38 | default=None, 39 | metadata=dataclass_config(exclude=lambda f: True), 40 | ) 41 | # pylint: enable=W0511 42 | stream_memory: Optional[io.BytesIO] = field( 43 | default=None, 44 | metadata=dataclass_config(exclude=lambda f: True), 45 | ) 46 | -------------------------------------------------------------------------------- /deepgram/clients/speak/v1/websocket/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from .client import SpeakWebSocketClient, SpeakWSClient 6 | from .async_client import AsyncSpeakWebSocketClient, AsyncSpeakWSClient 7 | from .response import ( 8 | #### top level 9 | MetadataResponse, 10 | FlushedResponse, 11 | ClearedResponse, 12 | WarningResponse, 13 | #### shared 14 | OpenResponse, 15 | CloseResponse, 16 | UnhandledResponse, 17 | ErrorResponse, 18 | ) 19 | from .options import SpeakWSOptions 20 | -------------------------------------------------------------------------------- /deepgram/clients/speak/v1/websocket/options.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from io import BufferedReader 6 | from typing import Union, Optional 7 | import logging 8 | 9 | from dataclasses import dataclass, field 10 | from dataclasses_json import config as dataclass_config 11 | 12 | from .....utils import verboselogs 13 | from ....common import BaseResponse 14 | 15 | 16 | @dataclass 17 | class SpeakWSOptions(BaseResponse): 18 | """ 19 | Contains all the options for the SpeakOptions. 20 | 21 | Reference: 22 | https://developers.deepgram.com/reference/transform-text-to-speech-websocket 23 | """ 24 | 25 | model: Optional[str] = field( 26 | default="aura-2-thalia-en", 27 | metadata=dataclass_config(exclude=lambda f: f is None), 28 | ) 29 | encoding: Optional[str] = field( 30 | default=None, metadata=dataclass_config(exclude=lambda f: f is None) 31 | ) 32 | # container: Optional[str] = field( 33 | # default=None, metadata=dataclass_config(exclude=lambda f: f is None) 34 | # ) 35 | sample_rate: Optional[int] = field( 36 | default=None, metadata=dataclass_config(exclude=lambda f: f is None) 37 | ) 38 | bit_rate: Optional[int] = field( 39 | default=None, metadata=dataclass_config(exclude=lambda f: f is None) 40 | ) 41 | 42 | def __getitem__(self, key): 43 | _dict = self.to_dict() 44 | return _dict[key] 45 | 46 | def __setitem__(self, key, val): 47 | self.__dict__[key] = val 48 | 49 | def __str__(self) -> str: 50 | return self.to_json(indent=4) 51 | 52 | def check(self): 53 | """ 54 | Check the SpeakOptions for any missing or invalid values. 55 | """ 56 | logger = verboselogs.VerboseLogger(__name__) 57 | logger.addHandler(logging.StreamHandler()) 58 | prev = logger.level 59 | logger.setLevel(verboselogs.ERROR) 60 | 61 | # no op at the moment 62 | 63 | logger.setLevel(prev) 64 | 65 | return True 66 | -------------------------------------------------------------------------------- /deepgram/clients/speak/v1/websocket/response.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | 6 | from dataclasses import dataclass 7 | 8 | from ....common import ( 9 | BaseResponse, 10 | OpenResponse, 11 | CloseResponse, 12 | ErrorResponse, 13 | UnhandledResponse, 14 | ) 15 | 16 | 17 | # Speak Response Types: 18 | 19 | 20 | @dataclass 21 | class MetadataResponse(BaseResponse): 22 | """ 23 | Metadata object 24 | """ 25 | 26 | type: str = "" 27 | request_id: str = "" 28 | 29 | 30 | @dataclass 31 | class FlushedResponse(BaseResponse): 32 | """ 33 | Flushed Message from the Deepgram Platform 34 | """ 35 | 36 | type: str = "" 37 | sequence_id: int = 0 38 | 39 | 40 | @dataclass 41 | class ClearedResponse(BaseResponse): 42 | """ 43 | Cleared object 44 | """ 45 | 46 | type: str = "" 47 | sequence_id: int = 0 48 | 49 | 50 | @dataclass 51 | class WarningResponse(BaseResponse): 52 | """ 53 | Warning Message from the Deepgram Platform 54 | """ 55 | 56 | warn_code: str = "" 57 | warn_msg: str = "" 58 | type: str = "" 59 | -------------------------------------------------------------------------------- /deepgram/errors.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | 6 | class DeepgramApiKeyError(Exception): 7 | """ 8 | Base class for exceptions raised for a missing Deepgram API Key. 9 | 10 | Attributes: 11 | message (str): The error message describing the exception. 12 | """ 13 | 14 | def __init__(self, message: str): 15 | super().__init__(message) 16 | self.name = "DeepgramApiKeyError" 17 | -------------------------------------------------------------------------------- /deepgram/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import logging 6 | from .verboselogs import VerboseLogger 7 | from .verboselogs import ( 8 | NOTICE, 9 | SPAM, 10 | SUCCESS, 11 | VERBOSE, 12 | WARNING, 13 | ERROR, 14 | FATAL, 15 | CRITICAL, 16 | INFO, 17 | DEBUG, 18 | NOTSET, 19 | ) 20 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | # Examples for Testing Features Locally 2 | 3 | The example projects are meant to be used to test features locally by contributors working on this SDK. 4 | 5 | ## Prerequisites 6 | 7 | In order to run the code in the `examples` folder, you first need to: 8 | 9 | 1. install/pip the dependencies contained in the `requirements-examples.txt` for the examples 10 | 2. be using a MacOS or Linux. These examples are geared towards non-windows platforms only. 11 | 12 | ```bash 13 | pip install -r requirements-examples.txt 14 | ``` 15 | 16 | | **IMPORTANT:** The microphone examples may not work out-of-the-box on Windows due to the portaudio dependency. Modifications to the example code and correct installation/configuration of the portaudio library are required. 17 | 18 | ## Steps to Test Your Code 19 | 20 | If you are contributing changes to this SDK, you can test those changes by using the `prerecorded`, `streaming`, or `manage` "hello world"-style applications in the `examples` folder. Here are the steps to follow: 21 | 22 | ### Set your API Key as an Environment Variable named "DEEPGRAM_API_KEY" 23 | 24 | If using bash, this could be done in your `.bash_profile` like so: 25 | 26 | ```bash 27 | export DEEPGRAM_API_KEY = "YOUR_DEEPGRAM_API_KEY" 28 | ``` 29 | 30 | or this could also be done by a simple export before executing your python application: 31 | 32 | ```bash 33 | DEEPGRAM_API_KEY="YOUR_DEEPGRAM_API_KEY" python main.py 34 | ``` 35 | 36 | ### Run the project 37 | 38 | If you chose to set an environment variable in your shell profile (ie `.bash_profile`) you can change directory into each example folder and run the example like so: 39 | 40 | ```bash 41 | python main.py 42 | ``` 43 | -------------------------------------------------------------------------------- /examples/advanced/README.md: -------------------------------------------------------------------------------- 1 | # Advanced Examples 2 | 3 | These are advanced examples that should not be used unless you understand advanced concepts in the Python language or with programming in general. 4 | 5 | ## Prerequisites 6 | 7 | Please see the README.md one folder up in the `examples` folder. 8 | 9 | ## Advanced Examples 10 | 11 | Here are some advanced examples: 12 | 13 | - Prerecorded 14 | 15 | - [examples/advanced/prerecorded/direct-invocation](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/advanced/prerecorded/direct-invocation/main.py) - Directly instaniate the Prerecorded classes in this SDK 16 | 17 | - Streaming: 18 | 19 | - [examples/advanced/streaming/direct-invocation](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/advanced/streaming/direct-invocation/main.py) - Directly instaniate the Live/Streaming classes in this SDK 20 | - [examples/advanced/streaming/microphone-inheritance](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/advanced/streaming//microphone-inheritance/main.py) - Extend the LiveClient class -------------------------------------------------------------------------------- /examples/advanced/rest/direct_invocation/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import os 6 | from dotenv import load_dotenv 7 | import logging 8 | from deepgram.utils import verboselogs 9 | import traceback 10 | 11 | from deepgram import ClientOptionsFromEnv, PrerecordedOptions, ListenRESTClient 12 | 13 | load_dotenv() 14 | 15 | AUDIO_URL = { 16 | "url": "https://static.deepgram.com/examples/Bueller-Life-moves-pretty-fast.wav" 17 | } 18 | 19 | 20 | def main(): 21 | try: 22 | # STEP 1 Create a Deepgram ListenRESTClient using a specific config 23 | # config: ClientOptionsFromEnv = ClientOptionsFromEnv( 24 | # verbose=verboselogs.NOTICE, 25 | # ) 26 | # asyncClient: ListenRESTClient = ListenRESTClient(config) 27 | # OR just use the default config 28 | asyncClient: ListenRESTClient = ListenRESTClient(ClientOptionsFromEnv()) 29 | 30 | # STEP 2 Call the transcribe_url method on the prerecorded class 31 | options: PrerecordedOptions = PrerecordedOptions( 32 | model="nova-3", 33 | smart_format=True, 34 | summarize="v2", 35 | ) 36 | response = asyncClient.transcribe_url(AUDIO_URL, options) 37 | print(response.to_json(indent=4)) 38 | 39 | except Exception as e: 40 | print(f"Exception: {e}") 41 | # enable the following line to print the stack trace 42 | # traceback.print_exc() 43 | 44 | 45 | if __name__ == "__main__": 46 | main() 47 | -------------------------------------------------------------------------------- /examples/advanced/websocket/microphone_inheritance/README.md: -------------------------------------------------------------------------------- 1 | # Live API (Real-Time) Example 2 | 3 | This example uses the Microphone as input in order to detect conversation insights in what is being said. This example required additional components (for the microphone) to be installed in order for this example to function correctly. 4 | 5 | ## Configuration 6 | 7 | The SDK (and this example) needs to be initialized with your account's credentials `DEEPGRAM_API_KEY`, which are available in your [Deepgram Console][dg-console]. If you don't have a Deepgram account, you can [sign up here][dg-signup] for free. 8 | 9 | You must add your `DEEPGRAM_API_KEY` to your list of environment variables. We use environment variables because they are easy to configure, support PaaS-style deployments, and work well in containerized environments like Docker and Kubernetes. 10 | 11 | ```bash 12 | export DEEPGRAM_API_KEY=YOUR-APP-KEY-HERE 13 | ``` 14 | 15 | ## Installation 16 | 17 | The Live API (Real-Time) example makes use of a [microphone package](https://github.com/deepgram/deepgram-python-sdk/tree/main/deepgram/audio/microphone) contained within the repository. That package makes use of the [PortAudio library](http://www.portaudio.com/) which is a cross-platform open source audio library. If you are on Linux, you can install this library using whatever package manager is available (yum, apt, etc.) on your operating system. If you are on macOS, you can install this library using [brew](https://brew.sh/). 18 | 19 | [dg-console]: https://console.deepgram.com/ 20 | [dg-signup]: https://console.deepgram.com/signup 21 | -------------------------------------------------------------------------------- /examples/analyze/intent/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import os 6 | from dotenv import load_dotenv 7 | import logging 8 | from deepgram.utils import verboselogs 9 | from datetime import datetime, timedelta 10 | 11 | from deepgram import ( 12 | DeepgramClient, 13 | DeepgramClientOptions, 14 | AnalyzeOptions, 15 | TextSource, 16 | ) 17 | 18 | load_dotenv() 19 | 20 | TEXT_FILE = "conversation.txt" 21 | 22 | 23 | def main(): 24 | try: 25 | # STEP 1 Create a Deepgram client using the API key in the environment variables 26 | # config: DeepgramClientOptions = DeepgramClientOptions( 27 | # verbose=verboselogs.SPAM, 28 | # ) 29 | # deepgram: DeepgramClient = DeepgramClient("", config) 30 | # OR use defaults 31 | deepgram: DeepgramClient = DeepgramClient() 32 | 33 | # STEP 2 Call the transcribe_file method on the prerecorded class 34 | with open(TEXT_FILE, "r") as file: 35 | buffer_data = file.read() 36 | 37 | payload: TextSource = { 38 | "buffer": buffer_data, 39 | } 40 | 41 | options: AnalyzeOptions = AnalyzeOptions( 42 | language="en", 43 | intents=True, 44 | ) 45 | 46 | before = datetime.now() 47 | response = deepgram.read.analyze.v("1").analyze_text(payload, options) 48 | after = datetime.now() 49 | 50 | print(response.to_json(indent=4)) 51 | print("") 52 | difference = after - before 53 | print(f"time: {difference.seconds}") 54 | 55 | except Exception as e: 56 | print(f"Exception: {e}") 57 | 58 | 59 | if __name__ == "__main__": 60 | main() 61 | -------------------------------------------------------------------------------- /examples/analyze/legacy_dict_intent/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import os 6 | from dotenv import load_dotenv 7 | import logging 8 | from deepgram.utils import verboselogs 9 | from datetime import datetime, timedelta 10 | 11 | from deepgram import ( 12 | DeepgramClient, 13 | DeepgramClientOptions, 14 | AnalyzeOptions, 15 | TextSource, 16 | ) 17 | 18 | load_dotenv() 19 | 20 | TEXT_FILE = "conversation.txt" 21 | 22 | 23 | def main(): 24 | try: 25 | # STEP 1 Create a Deepgram client using the API key in the environment variables 26 | # config = DeepgramClientOptions( 27 | # verbose=verboselogs.SPAM, 28 | # ) 29 | # deepgram = DeepgramClient("", config) 30 | # OR use defaults 31 | deepgram = DeepgramClient() 32 | 33 | # STEP 2 Call the transcribe_file method on the prerecorded class 34 | with open(TEXT_FILE, "r") as file: 35 | buffer_data = file.read() 36 | 37 | payload: TextSource = { 38 | "buffer": buffer_data, 39 | } 40 | 41 | options = { 42 | "language": "en", 43 | "intents": True, 44 | } 45 | 46 | before = datetime.now() 47 | response = deepgram.read.analyze.v("1").analyze_text(payload, options) 48 | after = datetime.now() 49 | 50 | print(response.to_json(indent=4)) 51 | print("") 52 | difference = after - before 53 | print(f"time: {difference.seconds}") 54 | 55 | except Exception as e: 56 | print(f"Exception: {e}") 57 | 58 | 59 | if __name__ == "__main__": 60 | main() 61 | -------------------------------------------------------------------------------- /examples/analyze/sentiment/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import os 6 | from dotenv import load_dotenv 7 | import logging 8 | from deepgram.utils import verboselogs 9 | from datetime import datetime, timedelta 10 | 11 | from deepgram import ( 12 | DeepgramClient, 13 | DeepgramClientOptions, 14 | AnalyzeOptions, 15 | TextSource, 16 | ) 17 | 18 | load_dotenv() 19 | 20 | TEXT_FILE = "conversation.txt" 21 | 22 | 23 | def main(): 24 | try: 25 | # STEP 1 Create a Deepgram client using the API key in the environment variables 26 | # config: DeepgramClientOptions = DeepgramClientOptions( 27 | # verbose=verboselogs.SPAM, 28 | # ) 29 | # deepgram: DeepgramClient = DeepgramClient("", config) 30 | # OR use defaults 31 | deepgram: DeepgramClient = DeepgramClient() 32 | 33 | # STEP 2 Call the transcribe_file method on the prerecorded class 34 | with open(TEXT_FILE, "r") as file: 35 | buffer_data = file.read() 36 | 37 | payload: TextSource = { 38 | "buffer": buffer_data, 39 | } 40 | 41 | options: AnalyzeOptions = AnalyzeOptions( 42 | language="en", 43 | sentiment=True, 44 | ) 45 | 46 | before = datetime.now() 47 | response = deepgram.read.analyze.v("1").analyze_text(payload, options) 48 | after = datetime.now() 49 | 50 | print(response.to_json(indent=4)) 51 | print("") 52 | difference = after - before 53 | print(f"time: {difference.seconds}") 54 | 55 | except Exception as e: 56 | print(f"Exception: {e}") 57 | 58 | 59 | if __name__ == "__main__": 60 | main() 61 | -------------------------------------------------------------------------------- /examples/analyze/stream_intent/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import os 6 | from dotenv import load_dotenv 7 | import logging 8 | from deepgram.utils import verboselogs 9 | from datetime import datetime, timedelta 10 | from io import BufferedReader 11 | from deepgram import DeepgramClientOptions 12 | import logging 13 | 14 | from deepgram import ( 15 | DeepgramClient, 16 | DeepgramClientOptions, 17 | AnalyzeStreamSource, 18 | AnalyzeOptions, 19 | ) 20 | 21 | load_dotenv() 22 | 23 | TEXT_FILE = "conversation.txt" 24 | 25 | 26 | def main(): 27 | try: 28 | # STEP 1 Create a Deepgram client using the API key in the environment variables 29 | config = DeepgramClientOptions( 30 | verbose=verboselogs.SPAM, 31 | ) 32 | deepgram = DeepgramClient("", config) 33 | 34 | # OR use defaults 35 | # deepgram = DeepgramClient() 36 | 37 | # STEP 2 Call the transcribe_file method on the prerecorded class 38 | stream = open(TEXT_FILE, "rb") 39 | 40 | payload: AnalyzeStreamSource = { 41 | "stream": stream, 42 | } 43 | 44 | options = AnalyzeOptions( 45 | language="en", 46 | intents=True, 47 | ) 48 | 49 | response = deepgram.read.analyze.v("1").analyze_text(payload, options) 50 | print(response.to_json(indent=4)) 51 | 52 | except Exception as e: 53 | print(f"Exception: {e}") 54 | 55 | 56 | if __name__ == "__main__": 57 | main() 58 | -------------------------------------------------------------------------------- /examples/analyze/summary/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import os 6 | from dotenv import load_dotenv 7 | import logging 8 | from deepgram.utils import verboselogs 9 | from datetime import datetime, timedelta 10 | 11 | from deepgram import ( 12 | DeepgramClient, 13 | DeepgramClientOptions, 14 | AnalyzeOptions, 15 | TextSource, 16 | ) 17 | 18 | load_dotenv() 19 | 20 | TEXT_FILE = "conversation.txt" 21 | 22 | 23 | def main(): 24 | try: 25 | # STEP 1 Create a Deepgram client using the API key in the environment variables 26 | # config: DeepgramClientOptions = DeepgramClientOptions( 27 | # verbose=verboselogs.SPAM, 28 | # ) 29 | # deepgram: DeepgramClient = DeepgramClient("", config) 30 | # OR use defaults 31 | deepgram: DeepgramClient = DeepgramClient() 32 | 33 | # STEP 2 Call the transcribe_file method on the prerecorded class 34 | with open(TEXT_FILE, "r") as file: 35 | buffer_data = file.read() 36 | 37 | payload: TextSource = { 38 | "buffer": buffer_data, 39 | } 40 | 41 | options: AnalyzeOptions = AnalyzeOptions( 42 | language="en", 43 | summarize=True, 44 | ) 45 | 46 | before = datetime.now() 47 | response = deepgram.read.analyze.v("1").analyze_text(payload, options) 48 | after = datetime.now() 49 | 50 | print(response.to_json(indent=4)) 51 | print("") 52 | difference = after - before 53 | print(f"time: {difference.seconds}") 54 | 55 | except Exception as e: 56 | print(f"Exception: {e}") 57 | 58 | 59 | if __name__ == "__main__": 60 | main() 61 | -------------------------------------------------------------------------------- /examples/analyze/topic/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import os 6 | from dotenv import load_dotenv 7 | import logging 8 | from deepgram.utils import verboselogs 9 | from datetime import datetime, timedelta 10 | 11 | from deepgram import ( 12 | DeepgramClient, 13 | DeepgramClientOptions, 14 | AnalyzeOptions, 15 | TextSource, 16 | ) 17 | 18 | load_dotenv() 19 | 20 | TEXT_FILE = "conversation.txt" 21 | 22 | 23 | def main(): 24 | try: 25 | # STEP 1 Create a Deepgram client using the API key in the environment variables 26 | # config: DeepgramClientOptions = DeepgramClientOptions( 27 | # verbose=verboselogs.SPAM, 28 | # ) 29 | # deepgram: DeepgramClient = DeepgramClient("", config) 30 | # OR use defaults 31 | deepgram: DeepgramClient = DeepgramClient() 32 | 33 | # STEP 2 Call the transcribe_file method on the prerecorded class 34 | with open(TEXT_FILE, "r") as file: 35 | buffer_data = file.read() 36 | 37 | payload: TextSource = { 38 | "buffer": buffer_data, 39 | } 40 | 41 | options: AnalyzeOptions = AnalyzeOptions( 42 | language="en", 43 | topics=True, 44 | ) 45 | 46 | before = datetime.now() 47 | response = deepgram.read.analyze.v("1").analyze_text(payload, options) 48 | after = datetime.now() 49 | 50 | print(response.to_json(indent=4)) 51 | print("") 52 | difference = after - before 53 | print(f"time: {difference.seconds}") 54 | 55 | except Exception as e: 56 | print(f"Exception: {e}") 57 | 58 | 59 | if __name__ == "__main__": 60 | main() 61 | -------------------------------------------------------------------------------- /examples/auth/async_token/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import asyncio 6 | import os 7 | from dotenv import load_dotenv 8 | from deepgram.utils import verboselogs 9 | 10 | from deepgram import ( 11 | DeepgramClient, 12 | DeepgramClientOptions 13 | ) 14 | 15 | load_dotenv() 16 | 17 | async def main(): 18 | try: 19 | # STEP 1 Create a Deepgram client using the DEEPGRAM_API_KEY from your environment variables 20 | config = DeepgramClientOptions( 21 | verbose=verboselogs.SPAM, 22 | ) 23 | deepgram: DeepgramClient = DeepgramClient(os.getenv("DEEPGRAM_API_KEY", ""), config) 24 | 25 | # STEP 2 Call the grant_token method on the auth rest class 26 | response = await deepgram.asyncauth.v("1").grant_token() 27 | print(f"response: {response}\n\n") 28 | except Exception as e: 29 | print(f"Exception: {e}") 30 | 31 | 32 | if __name__ == "__main__": 33 | asyncio.run(main()) 34 | -------------------------------------------------------------------------------- /examples/auth/token/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import os 6 | from dotenv import load_dotenv 7 | from deepgram.utils import verboselogs 8 | 9 | from deepgram import ( 10 | DeepgramClient, 11 | DeepgramClientOptions 12 | ) 13 | 14 | load_dotenv() 15 | 16 | def main(): 17 | try: 18 | # STEP 1 Create a Deepgram client using the DEEPGRAM_API_KEY from your environment variables 19 | config = DeepgramClientOptions( 20 | verbose=verboselogs.SPAM, 21 | ) 22 | deepgram: DeepgramClient = DeepgramClient(os.getenv("DEEPGRAM_API_KEY", ""), config) 23 | 24 | # STEP 2 Call the grant_token method on the auth rest class 25 | response = deepgram.auth.v("1").grant_token() 26 | print(f"response: {response}\n\n") 27 | except Exception as e: 28 | print(f"Exception: {e}") 29 | 30 | 31 | if __name__ == "__main__": 32 | main() 33 | -------------------------------------------------------------------------------- /examples/manage/async_invitations/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import asyncio 6 | import sys 7 | from dotenv import load_dotenv 8 | 9 | from deepgram import DeepgramClient, InviteOptions 10 | 11 | load_dotenv() 12 | 13 | 14 | async def main(): 15 | try: 16 | # Create a Deepgram client using the API key 17 | deepgram: DeepgramClient = DeepgramClient() 18 | 19 | # get projects 20 | projectResp = await deepgram.asyncmanage.v("1").get_projects() 21 | if projectResp is None: 22 | print(f"ListProjects failed.") 23 | sys.exit(1) 24 | 25 | myId = None 26 | myName = None 27 | for project in projectResp.projects: 28 | myId = project.project_id 29 | myName = project.name 30 | print(f"ListProjects() - ID: {myId}, Name: {myName}") 31 | break 32 | 33 | # list invites 34 | listResp = await deepgram.asyncmanage.v("1").get_invites(myId) 35 | if len(listResp.invites) == 0: 36 | print("No invites found") 37 | else: 38 | for invite in listResp.invites: 39 | print(f"GetInvites() - Name: {invite.email}, Amount: {invite.scope}") 40 | 41 | # send invite 42 | options: InviteOptions = {"email": "spam@spam.com", "scope": "member"} 43 | 44 | getResp = await deepgram.asyncmanage.v("1").send_invite_options(myId, options) 45 | print(f"SendInvite() - Msg: {getResp.message}") 46 | 47 | # list invites 48 | listResp = await deepgram.asyncmanage.v("1").get_invites(myId) 49 | if listResp is None: 50 | print("No invites found") 51 | else: 52 | for invite in listResp.invites: 53 | print(f"GetInvites() - Name: {invite.email}, Amount: {invite.scope}") 54 | 55 | # delete invite 56 | delResp = await deepgram.asyncmanage.v("1").delete_invite(myId, "spam@spam.com") 57 | print(f"DeleteInvite() - Msg: {delResp.message}") 58 | 59 | # # leave invite 60 | # delResp = await deepgram.asyncmanage.leave_project(myId) 61 | # print(f"LeaveProject() - Msg: {delResp.message}") 62 | except Exception as e: 63 | print(f"Exception: {e}") 64 | 65 | 66 | if __name__ == "__main__": 67 | asyncio.run(main()) 68 | -------------------------------------------------------------------------------- /examples/manage/balances/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import os 6 | import sys 7 | from dotenv import load_dotenv 8 | import logging 9 | from deepgram.utils import verboselogs 10 | 11 | from deepgram import DeepgramClient, DeepgramClientOptions 12 | 13 | load_dotenv() 14 | 15 | 16 | def main(): 17 | try: 18 | # STEP 1 Create a Deepgram client using the API key in the environment variables 19 | config: DeepgramClientOptions = DeepgramClientOptions( 20 | verbose=verboselogs.SPAM, 21 | ) 22 | deepgram: DeepgramClient = DeepgramClient("", config) 23 | # OR use defaults 24 | # deepgram: DeepgramClient = DeepgramClient() 25 | 26 | # get projects 27 | projectResp = deepgram.manage.v("1").get_projects() 28 | if projectResp is None: 29 | print(f"ListProjects failed.") 30 | sys.exit(1) 31 | 32 | myId = None 33 | myName = None 34 | for project in projectResp.projects: 35 | myId = project.project_id 36 | myName = project.name 37 | print(f"ListProjects() - ID: {myId}, Name: {myName}") 38 | break 39 | 40 | # list balances 41 | listResp = deepgram.manage.v("1").get_balances(myId) 42 | if listResp is None: 43 | print(f"ListBalances failed.") 44 | sys.exit(1) 45 | 46 | myBalanceId = None 47 | for balance in listResp.balances: 48 | myBalanceId = balance.balance_id 49 | print( 50 | f"GetBalance() - Name: {balance.balance_id}, Amount: {balance.amount}" 51 | ) 52 | 53 | # get balance 54 | getResp = deepgram.manage.v("1").get_balance(myId, myBalanceId) 55 | print(f"GetBalance() - Name: {getResp.balance_id}, Amount: {getResp.amount}") 56 | except Exception as e: 57 | print(f"Exception: {e}") 58 | 59 | 60 | if __name__ == "__main__": 61 | main() 62 | -------------------------------------------------------------------------------- /examples/manage/invitations/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import os 6 | import sys 7 | from dotenv import load_dotenv 8 | 9 | from deepgram import DeepgramClient, InviteOptions 10 | 11 | load_dotenv() 12 | 13 | 14 | def main(): 15 | try: 16 | # Create a Deepgram client using the API key 17 | deepgram: DeepgramClient = DeepgramClient() 18 | 19 | # get projects 20 | projectResp = deepgram.manage.v("1").get_projects() 21 | if projectResp is None: 22 | print(f"ListProjects failed.") 23 | sys.exit(1) 24 | 25 | myId = None 26 | myName = None 27 | for project in projectResp.projects: 28 | myId = project.project_id 29 | myName = project.name 30 | print(f"ListProjects() - ID: {myId}, Name: {myName}") 31 | break 32 | 33 | # list invites 34 | listResp = deepgram.manage.v("1").get_invites(myId) 35 | if len(listResp.invites) == 0: 36 | print("No invites found") 37 | else: 38 | for invite in listResp.invites: 39 | print(f"GetInvites() - Name: {invite.email}, Amount: {invite.scope}") 40 | 41 | # send invite 42 | options = InviteOptions(email="spam@spam.com", scope="member") 43 | 44 | getResp = deepgram.manage.v("1").send_invite_options(myId, options) 45 | print(f"SendInvite() - Msg: {getResp.message}") 46 | 47 | # list invites 48 | listResp = deepgram.manage.v("1").get_invites(myId) 49 | if listResp is None: 50 | print("No invites found") 51 | else: 52 | for invite in listResp.invites: 53 | print(f"GetInvites() - Name: {invite.email}, Amount: {invite.scope}") 54 | 55 | # delete invite 56 | delResp = deepgram.manage.v("1").delete_invite(myId, "spam@spam.com") 57 | print(f"DeleteInvite() - Msg: {delResp.message}") 58 | 59 | # # leave invite 60 | # delResp = deepgram.manage.v("1").leave_project(myId) 61 | # print(f"LeaveProject() - Msg: {delResp.message}") 62 | except Exception as e: 63 | print(f"Exception: {e}") 64 | 65 | 66 | if __name__ == "__main__": 67 | main() 68 | -------------------------------------------------------------------------------- /examples/manage/legacy_dict_invitations/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import os 6 | import sys 7 | from dotenv import load_dotenv 8 | 9 | from deepgram import DeepgramClient, InviteOptions 10 | 11 | load_dotenv() 12 | 13 | 14 | def main(): 15 | try: 16 | # Create a Deepgram client using the API key 17 | deepgram = DeepgramClient() 18 | 19 | # get projects 20 | projectResp = deepgram.manage.v("1").get_projects() 21 | if projectResp is None: 22 | print(f"ListProjects failed.") 23 | sys.exit(1) 24 | 25 | myId = None 26 | myName = None 27 | for project in projectResp.projects: 28 | myId = project.project_id 29 | myName = project.name 30 | print(f"ListProjects() - ID: {myId}, Name: {myName}") 31 | break 32 | 33 | # list invites 34 | listResp = deepgram.manage.v("1").get_invites(myId) 35 | if len(listResp.invites) == 0: 36 | print("No invites found") 37 | else: 38 | for invite in listResp.invites: 39 | print(f"GetInvites() - Name: {invite.email}, Amount: {invite.scope}") 40 | 41 | # send invite 42 | options = { 43 | "email": "spam@spam.com", 44 | "scope": "member", 45 | } 46 | 47 | getResp = deepgram.manage.v("1").send_invite_options(myId, options) 48 | print(f"SendInvite() - Msg: {getResp.message}") 49 | 50 | # list invites 51 | listResp = deepgram.manage.v("1").get_invites(myId) 52 | if listResp is None: 53 | print("No invites found") 54 | else: 55 | for invite in listResp.invites: 56 | print(f"GetInvites() - Name: {invite.email}, Amount: {invite.scope}") 57 | 58 | # delete invite 59 | delResp = deepgram.manage.v("1").delete_invite(myId, "spam@spam.com") 60 | print(f"DeleteInvite() - Msg: {delResp.message}") 61 | 62 | # # leave invite 63 | # delResp = deepgram.manage.v("1").leave_project(myId) 64 | # print(f"LeaveProject() - Msg: {delResp.message}") 65 | except Exception as e: 66 | print(f"Exception: {e}") 67 | 68 | 69 | if __name__ == "__main__": 70 | main() 71 | -------------------------------------------------------------------------------- /examples/requirements-examples.txt: -------------------------------------------------------------------------------- 1 | # pip install -r requirements-examples.txt 2 | 3 | # general 4 | python-dotenv 5 | requests 6 | 7 | # streaming libs 8 | pyaudio 9 | playsound3==2.2.1 10 | sounddevice==0.4.7 11 | numpy==2.0.1 12 | -------------------------------------------------------------------------------- /examples/speech-to-text/rest/async/file/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import asyncio 6 | import aiofiles 7 | from dotenv import load_dotenv 8 | import logging 9 | from deepgram.utils import verboselogs 10 | from datetime import datetime 11 | import httpx 12 | 13 | from deepgram import ( 14 | DeepgramClient, 15 | DeepgramClientOptions, 16 | PrerecordedOptions, 17 | FileSource, 18 | ) 19 | 20 | load_dotenv() 21 | 22 | AUDIO_FILE = "preamble.wav" 23 | 24 | 25 | async def main(): 26 | try: 27 | # STEP 1 Create a Deepgram client using the API key in the environment variables 28 | config: DeepgramClientOptions = DeepgramClientOptions( 29 | verbose=verboselogs.SPAM, 30 | ) 31 | deepgram: DeepgramClient = DeepgramClient("", config) 32 | # OR use defaults 33 | # deepgram: DeepgramClient = DeepgramClient() 34 | 35 | # STEP 2 Call the transcribe_file method on the rest class 36 | async with aiofiles.open(AUDIO_FILE, "rb") as file: 37 | buffer_data = await file.read() 38 | 39 | payload: FileSource = { 40 | "buffer": buffer_data, 41 | } 42 | 43 | options: PrerecordedOptions = PrerecordedOptions( 44 | model="nova-3", 45 | smart_format=True, 46 | utterances=True, 47 | punctuate=True, 48 | diarize=True, 49 | ) 50 | 51 | before = datetime.now() 52 | response = await deepgram.listen.asyncrest.v("1").transcribe_file( 53 | payload, options, timeout=httpx.Timeout(300.0, connect=10.0) 54 | ) 55 | after = datetime.now() 56 | 57 | print(response.to_json(indent=4)) 58 | print("") 59 | difference = after - before 60 | print(f"time: {difference.seconds}") 61 | 62 | except Exception as e: 63 | print(f"Exception: {e}") 64 | 65 | 66 | if __name__ == "__main__": 67 | asyncio.run(main()) 68 | -------------------------------------------------------------------------------- /examples/speech-to-text/rest/async/file/preamble.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deepgram/deepgram-python-sdk/6380b56f810b31323aedf7b644c5a0466f48a1ee/examples/speech-to-text/rest/async/file/preamble.wav -------------------------------------------------------------------------------- /examples/speech-to-text/rest/async/url/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import asyncio 6 | import os 7 | from dotenv import load_dotenv 8 | 9 | from deepgram import DeepgramClient, PrerecordedOptions 10 | 11 | load_dotenv() 12 | 13 | API_KEY = os.getenv("DEEPGRAM_API_KEY") 14 | AUDIO_URL = { 15 | "url": "https://static.deepgram.com/examples/Bueller-Life-moves-pretty-fast.wav" 16 | } 17 | 18 | options: PrerecordedOptions = PrerecordedOptions( 19 | model="nova-3", 20 | smart_format=True, 21 | summarize="v2", 22 | ) 23 | 24 | # STEP 1 Create a Deepgram client using the API key (optional - add config options) 25 | deepgram: DeepgramClient = DeepgramClient(API_KEY) 26 | 27 | 28 | # STEP 2 Call the transcribe_url method on the rest class 29 | async def transcribe_url(): 30 | url_response = await deepgram.listen.asyncrest.v("1").transcribe_url( 31 | AUDIO_URL, options 32 | ) 33 | return url_response 34 | 35 | 36 | async def main(): 37 | try: 38 | response = await transcribe_url() 39 | print(response.to_json(indent=4)) 40 | except Exception as e: 41 | print(f"Exception: {e}") 42 | 43 | 44 | if __name__ == "__main__": 45 | asyncio.run(main()) 46 | -------------------------------------------------------------------------------- /examples/speech-to-text/rest/callback/README.md: -------------------------------------------------------------------------------- 1 | # Callback Example 2 | 3 | This example shows how to use the [Callback](https://developers.deepgram.com/docs/callback) functionality on the Prerecorded API. 4 | 5 | > **_NOTE:_** To use this example, the `endpoint` component must run somewhere with a public-facing IP address. You cannot run this example locally behind your typical firewall. 6 | 7 | ## Configuration 8 | 9 | This example consists of two components: 10 | - `endpoint`: which is an example of what a callback endpoint would look like. Reminder: this requires running with a public-facing IP address 11 | - `callback`: which is just a Deepgram client posts a PreRecorded transcription request using a local audio file preamble.wav (or using an audio file at a hosted URL, like [https://static.deepgram.com/examples/Bueller-Life-moves-pretty-fast.wav](https://static.deepgram.com/examples/Bueller-Life-moves-pretty-fast.wav). 12 | 13 | The `callback` component requires the Deepgram API Key environment variable to be configured to run. 14 | 15 | ```sh 16 | export DEEPGRAM_API_KEY=YOUR-APP-KEY-HERE 17 | ``` 18 | 19 | ### Prerequisites: Public-facing Endpoint 20 | 21 | This example requires that the Deepgram platform be able to reach your `endpoint` which means the IP address must be publically hosted. This could be an EC2 instance on AWS, an instance on GCP, etc. Another option is using [ngrok](https://ngrok.com/). 22 | 23 | `ngrok` brief overview: run ngrok http 8080 which opens up the local host port 8080, and gives a public URL https://e00a-42-156-98-177.ngrok-free.app/ (for example). Then in another terminal, run nc -l 8080 to listen on port 8080 for incoming messages. The `CALL_BACK_URL` should then be set to `https://e00a-42-156-98-177.ngrok-free.app`. 24 | 25 | ## Installation 26 | 27 | Run the `endpoint` application using an SSL certificate to a system on the public-facing internet. 28 | 29 | On the `callback` project, modify the IP address constant in the code with the public-facing IP address of your EC2, GCP, etc instance. 30 | 31 | ```Python 32 | CALL_BACK_URL = ( 33 | "https://127.0.0.1:8000" # TODO: MUST REPLACE WITH YOUR OWN CALLBACK ENDPOINT 34 | ) 35 | ``` 36 | 37 | Then run the `callback` application. This can be done from your local laptop. 38 | -------------------------------------------------------------------------------- /examples/speech-to-text/rest/callback/callback/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import os 6 | from dotenv import load_dotenv 7 | import logging 8 | from deepgram.utils import verboselogs 9 | from datetime import datetime, timedelta 10 | 11 | from deepgram import ( 12 | DeepgramClient, 13 | DeepgramClientOptions, 14 | PrerecordedOptions, 15 | FileSource, 16 | UrlSource, 17 | ) 18 | 19 | load_dotenv() 20 | 21 | AUDIO_FILE = "preamble.wav" 22 | CALL_BACK_URL = ( 23 | "https://127.0.0.1:8000" # TODO: MUST REPLACE WITH YOUR OWN CALLBACK ENDPOINT 24 | ) 25 | 26 | 27 | def main(): 28 | try: 29 | # STEP 1 Create a Deepgram client using the API key in the environment variables 30 | config: DeepgramClientOptions = DeepgramClientOptions( 31 | verbose=verboselogs.SPAM, 32 | ) 33 | 34 | deepgram: DeepgramClient = DeepgramClient("", config) 35 | 36 | # STEP 2 Call the transcribe_file method on the rest class 37 | with open(AUDIO_FILE, "rb") as file: 38 | buffer_data = file.read() 39 | 40 | payload: FileSource = { 41 | "buffer": buffer_data, 42 | } 43 | # For URL hosted audio files, comment out the above and uncomment the below 44 | # payload: UrlSource = { 45 | # "url": "https://static.deepgram.com/examples/Bueller-Life-moves-pretty-fast.wav" 46 | # } 47 | 48 | options: PrerecordedOptions = PrerecordedOptions( 49 | model="nova-3", 50 | smart_format=True, 51 | utterances=True, 52 | ) 53 | 54 | response = deepgram.listen.rest.v("1").transcribe_file_callback( 55 | payload, CALL_BACK_URL, options=options 56 | ) 57 | # For URL hosted audio files, comment out the above and uncomment the below 58 | # response = deepgram.listen.rest.v("1").transcribe_url_callback( 59 | # payload, CALL_BACK_URL, options=options 60 | # ) 61 | print(response.to_json(indent=4)) 62 | 63 | except Exception as e: 64 | print(f"Exception: {e}") 65 | 66 | 67 | if __name__ == "__main__": 68 | main() 69 | -------------------------------------------------------------------------------- /examples/speech-to-text/rest/callback/callback/preamble.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deepgram/deepgram-python-sdk/6380b56f810b31323aedf7b644c5a0466f48a1ee/examples/speech-to-text/rest/callback/callback/preamble.wav -------------------------------------------------------------------------------- /examples/speech-to-text/rest/callback/endpoint/localhost.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDoDCCAogCCQCtyWzcpdOQUDANBgkqhkiG9w0BAQUFADCBkTELMAkGA1UEBhMC 3 | VVMxCzAJBgNVBAgMAkNBMRMwEQYDVQQHDApMb25nIEJlYWNoMREwDwYDVQQKDAhT 4 | eW1ibC5haTEbMBkGA1UECwwSRGV2ZWxvcGVyIEFkdm9jYWN5MRIwEAYDVQQDDAkx 5 | MjcuMC4wLjExHDAaBgkqhkiG9w0BCQEWDXNwYW1Ac3ltYmwuYWkwHhcNMjIxMTIx 6 | MTYyOTM3WhcNMjMxMTIxMTYyOTM3WjCBkTELMAkGA1UEBhMCVVMxCzAJBgNVBAgM 7 | AkNBMRMwEQYDVQQHDApMb25nIEJlYWNoMREwDwYDVQQKDAhTeW1ibC5haTEbMBkG 8 | A1UECwwSRGV2ZWxvcGVyIEFkdm9jYWN5MRIwEAYDVQQDDAkxMjcuMC4wLjExHDAa 9 | BgkqhkiG9w0BCQEWDXNwYW1Ac3ltYmwuYWkwggEiMA0GCSqGSIb3DQEBAQUAA4IB 10 | DwAwggEKAoIBAQCv6xZu8caNs847YIVVsjE7odfcyFKsrIkXsUDyImkLNNLBCSQ8 11 | xMrNiVo4OoKwcpqGR1NsSoblFYoruE41gA5R2nbILIbNeu5Sq+Kqljtuci7kDog1 12 | OX8yliEVkSECJZ7uGGb811p8R9BDsZqUXk/gZTKknbYFon6fQkvbmucSBHHA98TC 13 | s3WhP/F7zCVwK1u3oX67TjfmN+RXkXwlC2FjnDjoc8TWRHtnV9Nv71i0ss5Ep6GB 14 | G6iwsM86C+bEhQYzGbT/oZexeP+1NuKBhhtXfvlo5aXP1RRfCGsCE5UcxVXE7Cid 15 | UGK0XQ9cHFgW8/axbP+WFWvbyqpE2hSFpZ3zAgMBAAEwDQYJKoZIhvcNAQEFBQAD 16 | ggEBAEsKMNI16CzuuM8dcLbzsxu490AEqlwbzCnEUqqEbe0m3z9rz3HTG6KV6ejc 17 | 2ABl0MtSxGeW4K6Vb0+AC61NXa0snnDVFHNd8McsVvSSpnwvVll8S7oCjFviDzu3 18 | FYDlhqI8c7SNJNjC5FL4fV0P7IwR8cN3wn0hfd3dKzxvTVvU5AWA3S33M494ewrt 19 | HZE1CTX6Al+hghjSXOrpd1yvD1UBlYvnASHh+whRlAN2V9IpZEo9IpQB12sj97lZ 20 | Lw+O53Ysn1PR0WuTdjgmtc3m//6QrHQOxcOLxl8Jyi0uXclFv8Oy0VmUbZe18MzA 21 | n70mi+NaDxTrsFCL9goHUjc6uhw= 22 | -----END CERTIFICATE----- 23 | -------------------------------------------------------------------------------- /examples/speech-to-text/rest/callback/endpoint/localhost.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIIC1zCCAb8CAQAwgZExCzAJBgNVBAYTAlVTMQswCQYDVQQIDAJDQTETMBEGA1UE 3 | BwwKTG9uZyBCZWFjaDERMA8GA1UECgwIU3ltYmwuYWkxGzAZBgNVBAsMEkRldmVs 4 | b3BlciBBZHZvY2FjeTESMBAGA1UEAwwJMTI3LjAuMC4xMRwwGgYJKoZIhvcNAQkB 5 | Fg1zcGFtQHN5bWJsLmFpMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA 6 | r+sWbvHGjbPOO2CFVbIxO6HX3MhSrKyJF7FA8iJpCzTSwQkkPMTKzYlaODqCsHKa 7 | hkdTbEqG5RWKK7hONYAOUdp2yCyGzXruUqviqpY7bnIu5A6INTl/MpYhFZEhAiWe 8 | 7hhm/NdafEfQQ7GalF5P4GUypJ22BaJ+n0JL25rnEgRxwPfEwrN1oT/xe8wlcCtb 9 | t6F+u0435jfkV5F8JQthY5w46HPE1kR7Z1fTb+9YtLLORKehgRuosLDPOgvmxIUG 10 | Mxm0/6GXsXj/tTbigYYbV375aOWlz9UUXwhrAhOVHMVVxOwonVBitF0PXBxYFvP2 11 | sWz/lhVr28qqRNoUhaWd8wIDAQABoAAwDQYJKoZIhvcNAQELBQADggEBAIB+1Lcx 12 | ywJvr3DQc3gkSNDZp5sR9hK65wjwt2dhzgbSBsbGPPyf0q54QCc9UPz37XSp/xkl 13 | vU1T12SMK53JIXwizoj47BM51hhrfIs0Ky6msrL2+FyAPBTQpYbVLg3AvqFZUejl 14 | Gj2kcG3nvTMtex3ktoHwOAfdvVhqWYqGomkQseVep6mAx/8soJycohtT6K255tyN 15 | IyMkNO8KZA+R8jVSjFIbMM5YG3dBqj//s0+Qb49dN/TybRmUAeuMQEnk737vzz63 16 | 1w/58UGpshqBOwf4/jz1nESxXvDOgGu8ygMbaBe/uEI68szTGGXl4FZvRy3nHDsz 17 | Nn5k5SNMwaAQkW0= 18 | -----END CERTIFICATE REQUEST----- 19 | -------------------------------------------------------------------------------- /examples/speech-to-text/rest/callback/endpoint/localhost.key: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCv6xZu8caNs847 3 | YIVVsjE7odfcyFKsrIkXsUDyImkLNNLBCSQ8xMrNiVo4OoKwcpqGR1NsSoblFYor 4 | uE41gA5R2nbILIbNeu5Sq+Kqljtuci7kDog1OX8yliEVkSECJZ7uGGb811p8R9BD 5 | sZqUXk/gZTKknbYFon6fQkvbmucSBHHA98TCs3WhP/F7zCVwK1u3oX67TjfmN+RX 6 | kXwlC2FjnDjoc8TWRHtnV9Nv71i0ss5Ep6GBG6iwsM86C+bEhQYzGbT/oZexeP+1 7 | NuKBhhtXfvlo5aXP1RRfCGsCE5UcxVXE7CidUGK0XQ9cHFgW8/axbP+WFWvbyqpE 8 | 2hSFpZ3zAgMBAAECggEAAkdoXf2R1eobZNeGQqrxSlV5Z2nM8GG30O/B6KEbfUKs 9 | 7EVDC+p8uhbqbUoMwV5qtAyefwukHbmetZxInxbOmK7c1REGmgjap4WEhTM3B+JA 10 | y0GI8C+Tf0NEoHPl2pJEMc9tHh9oE64We5oEZ6GlJUIKWumUHxSQ0V1ZgDnMfoY8 11 | ttl/NpShMF9lz67GnaMcGNwrXr2a/oKEXUdAuOZKyS9vP80WLWAYzLGSBa2FEMmJ 12 | tumLb8EEQpWRPOPTwylPAJcV/67FjH/g4DCA8NgyevI2/lH/ZHlp0UYC5vLqzN8Z 13 | zN4MalYC+6ZWZSM//gyhxvXZ3j+WNUERSv+ndTk+YQKBgQDabhzExPgpzgtnQpg5 14 | hnJpcGmxdp6ajFz70AI1sU6rWisAItwF8g6xHIH4TkHhhn3oyJ4Xtzt7jOaT011t 15 | IVmks2uNoONjO4yFmLvkQORn4opvkdya+gm68acceb3jdKI663MmfLLUXKaHVpwN 16 | zP0kzWuKD++kCtHMphqK3LKXMQKBgQDOLRmzE8pxNtXNvgBFCqwPiSxGNZ3nfi+t 17 | MIhW/YhW6RypeTQ/NFWzIzklO79VUQCUidRdEmh21XGisDxMtnIw+5VAKliE40Aw 18 | hGTxLn+HsQ1IPxD3/3bVJkU2Htpxfo4/WClRnZ9E3wD++6hayGtDY6peRrBY5plq 19 | t31dXyoGYwKBgQCPEAevqQKQ/u7hFvD03GYbQRE4tmRy/PP5yedom1TXThtT34EU 20 | M9IDlpRZuYfU2m2lBaDmD5DZ/xMWRx2t2GYKRalv/axw1hPXfI2zlf0DPZFGOdav 21 | eozc8GFveR0x2LZYuNWWo53NEVHQ2p0jPNugOxrwNjfSzXNUAobn5FzkQQKBgDPc 22 | alt+PezucydWhLDZN2CNC6L5d6e0OP/idlkTWwkph/klMLw5SNlPod84wS8Pugqj 23 | BNUIfVhu5i+bDv/o4J5rmiZSwINkuk+57b4xCQkzwviKTJVlIBoLj1tGtYHY6KUM 24 | YxBRiq+DPLfmy3lScpC38DHYrCEgmDScxR8IggSrAoGBAJldUpe90FsKz26Eef6s 25 | ZTbWRT9BB3GQc4IhtWr23RmOGEiORRglHtHRIzaBose23ZTjCa/A9hkF6p+vtqBf 26 | RUzmHCNtK7n5yQMhqJPiLLhVlyzApsUwtlNPvjIOn7a6wbHu5U/1nrYDlOicSATx 27 | QgUzTpG/aebRgw9E35figb4p 28 | -----END PRIVATE KEY----- 29 | -------------------------------------------------------------------------------- /examples/speech-to-text/rest/callback/endpoint/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from http.server import HTTPServer, BaseHTTPRequestHandler 6 | import ssl 7 | from io import BytesIO 8 | 9 | 10 | class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): 11 | def do_POST(self): 12 | content_length = int(self.headers["Content-Length"]) 13 | body = self.rfile.read(content_length) 14 | print("\n\n") 15 | print(f"body: {body}") 16 | print("\n\n") 17 | self.send_response(200) 18 | self.end_headers() 19 | 20 | 21 | def main(): 22 | context = ssl.SSLContext() 23 | context.load_cert_chain("localhost.crt", "localhost.key") 24 | 25 | httpd = HTTPServer(("localhost", 8000), SimpleHTTPRequestHandler) 26 | httpd.socket = context.wrap_socket( 27 | httpd.socket, 28 | server_side=True, 29 | ) 30 | httpd.serve_forever() 31 | 32 | 33 | if __name__ == "__main__": 34 | main() 35 | -------------------------------------------------------------------------------- /examples/speech-to-text/rest/intent/CallCenterPhoneCall.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deepgram/deepgram-python-sdk/6380b56f810b31323aedf7b644c5a0466f48a1ee/examples/speech-to-text/rest/intent/CallCenterPhoneCall.mp3 -------------------------------------------------------------------------------- /examples/speech-to-text/rest/intent/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import os 6 | from dotenv import load_dotenv 7 | import logging 8 | from deepgram.utils import verboselogs 9 | from datetime import datetime, timedelta 10 | 11 | from deepgram import ( 12 | DeepgramClient, 13 | DeepgramClientOptions, 14 | PrerecordedOptions, 15 | FileSource, 16 | ) 17 | 18 | load_dotenv() 19 | 20 | AUDIO_FILE = "CallCenterPhoneCall.mp3" 21 | 22 | 23 | def main(): 24 | try: 25 | # STEP 1 Create a Deepgram client using the API key in the environment variables 26 | # config: DeepgramClientOptions = DeepgramClientOptions( 27 | # verbose=verboselogs.SPAM, 28 | # ) 29 | # deepgram: DeepgramClient = DeepgramClient("", config) 30 | # OR use defaults 31 | deepgram: DeepgramClient = DeepgramClient() 32 | 33 | # STEP 2 Call the transcribe_file method on the rest class 34 | with open(AUDIO_FILE, "rb") as file: 35 | buffer_data = file.read() 36 | 37 | payload: FileSource = { 38 | "buffer": buffer_data, 39 | } 40 | 41 | options: PrerecordedOptions = PrerecordedOptions( 42 | model="nova-3", 43 | smart_format=True, 44 | utterances=True, 45 | punctuate=True, 46 | intents=True, 47 | ) 48 | 49 | before = datetime.now() 50 | response = deepgram.listen.rest.v("1").transcribe_file(payload, options) 51 | after = datetime.now() 52 | 53 | print(response.to_json(indent=4)) 54 | print("") 55 | difference = after - before 56 | print(f"time: {difference.seconds}") 57 | 58 | except Exception as e: 59 | print(f"Exception: {e}") 60 | 61 | 62 | if __name__ == "__main__": 63 | main() 64 | -------------------------------------------------------------------------------- /examples/speech-to-text/rest/legacy_dict_url/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import os 6 | from dotenv import load_dotenv 7 | import logging 8 | from deepgram.utils import verboselogs 9 | 10 | from deepgram import ( 11 | DeepgramClient, 12 | ClientOptionsFromEnv, 13 | PrerecordedOptions, 14 | ) 15 | 16 | load_dotenv() 17 | 18 | AUDIO_URL = { 19 | "url": "https://static.deepgram.com/examples/Bueller-Life-moves-pretty-fast.wav" 20 | } 21 | 22 | 23 | def main(): 24 | try: 25 | # STEP 1 Create a Deepgram client using the API key from environment variables 26 | deepgram = DeepgramClient("", ClientOptionsFromEnv()) 27 | 28 | # STEP 2 Call the transcribe_url method on the rest class 29 | options = { 30 | "mode": "nova-3", 31 | "smart_format": True, 32 | } 33 | response = deepgram.listen.rest.v("1").transcribe_url(AUDIO_URL, options) 34 | print(f"response: {response}\n\n") 35 | # print(f"metadata: {response['metadata']}\n\n") 36 | # print( 37 | # f"transcript: {response.results.channels[0].alternatives[0]['transcript']}\n\n" 38 | # ) 39 | # for word in response.results.channels[0].alternatives[0].words: 40 | # print(f"Word: {word.word}, Start: {word.start}, End: {word.end}") 41 | 42 | except Exception as e: 43 | print(f"Exception: {e}") 44 | 45 | 46 | if __name__ == "__main__": 47 | main() 48 | -------------------------------------------------------------------------------- /examples/speech-to-text/rest/sentiment/CallCenterPhoneCall.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deepgram/deepgram-python-sdk/6380b56f810b31323aedf7b644c5a0466f48a1ee/examples/speech-to-text/rest/sentiment/CallCenterPhoneCall.mp3 -------------------------------------------------------------------------------- /examples/speech-to-text/rest/sentiment/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import os 6 | from dotenv import load_dotenv 7 | import logging 8 | from deepgram.utils import verboselogs 9 | from datetime import datetime, timedelta 10 | 11 | from deepgram import ( 12 | DeepgramClient, 13 | DeepgramClientOptions, 14 | PrerecordedOptions, 15 | FileSource, 16 | ) 17 | 18 | load_dotenv() 19 | 20 | AUDIO_FILE = "CallCenterPhoneCall.mp3" 21 | 22 | 23 | def main(): 24 | try: 25 | # STEP 1 Create a Deepgram client using the API key in the environment variables 26 | # config: DeepgramClientOptions = DeepgramClientOptions( 27 | # verbose=verboselogs.SPAM, 28 | # ) 29 | # deepgram: DeepgramClient = DeepgramClient("", config) 30 | # OR use defaults 31 | deepgram: DeepgramClient = DeepgramClient() 32 | 33 | # STEP 2 Call the transcribe_file method on the rest class 34 | with open(AUDIO_FILE, "rb") as file: 35 | buffer_data = file.read() 36 | 37 | payload: FileSource = { 38 | "buffer": buffer_data, 39 | } 40 | 41 | options = PrerecordedOptions( 42 | model="nova-3", 43 | smart_format=True, 44 | utterances=True, 45 | punctuate=True, 46 | sentiment=True, 47 | ) 48 | 49 | before = datetime.now() 50 | response = deepgram.listen.rest.v("1").transcribe_file(payload, options) 51 | after = datetime.now() 52 | 53 | print(response.to_json(indent=4)) 54 | print("") 55 | difference = after - before 56 | print(f"time: {difference.seconds}") 57 | 58 | except Exception as e: 59 | print(f"Exception: {e}") 60 | 61 | 62 | if __name__ == "__main__": 63 | main() 64 | -------------------------------------------------------------------------------- /examples/speech-to-text/rest/stream_file/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import os 6 | from dotenv import load_dotenv 7 | import logging 8 | from deepgram.utils import verboselogs 9 | from datetime import datetime, timedelta 10 | from io import BufferedReader 11 | from deepgram import DeepgramClientOptions 12 | import logging 13 | 14 | from deepgram import ( 15 | DeepgramClient, 16 | DeepgramClientOptions, 17 | StreamSource, 18 | PrerecordedOptions, 19 | ) 20 | 21 | load_dotenv() 22 | 23 | AUDIO_FILE = "preamble.wav" 24 | 25 | 26 | def main(): 27 | try: 28 | # STEP 1 Create a Deepgram client using the API key in the environment variables 29 | config = DeepgramClientOptions( 30 | verbose=verboselogs.SPAM, 31 | ) 32 | deepgram = DeepgramClient("", config) 33 | # OR use defaults 34 | # deepgram = DeepgramClient() 35 | 36 | # STEP 2 Call the transcribe_file method on the rest class 37 | with open(AUDIO_FILE, "rb") as stream: 38 | payload: StreamSource = { 39 | "stream": stream, 40 | } 41 | options = PrerecordedOptions( 42 | model="nova-3", 43 | ) 44 | response = deepgram.listen.rest.v("1").transcribe_file(payload, options) 45 | print(response.to_json(indent=4)) 46 | 47 | except Exception as e: 48 | print(f"Exception: {e}") 49 | 50 | 51 | if __name__ == "__main__": 52 | main() 53 | -------------------------------------------------------------------------------- /examples/speech-to-text/rest/stream_file/preamble.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deepgram/deepgram-python-sdk/6380b56f810b31323aedf7b644c5a0466f48a1ee/examples/speech-to-text/rest/stream_file/preamble.wav -------------------------------------------------------------------------------- /examples/speech-to-text/rest/summary/CallCenterPhoneCall.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deepgram/deepgram-python-sdk/6380b56f810b31323aedf7b644c5a0466f48a1ee/examples/speech-to-text/rest/summary/CallCenterPhoneCall.mp3 -------------------------------------------------------------------------------- /examples/speech-to-text/rest/summary/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import os 6 | from dotenv import load_dotenv 7 | import logging 8 | from deepgram.utils import verboselogs 9 | from datetime import datetime, timedelta 10 | 11 | from deepgram import ( 12 | DeepgramClient, 13 | DeepgramClientOptions, 14 | PrerecordedOptions, 15 | FileSource, 16 | ) 17 | 18 | load_dotenv() 19 | 20 | AUDIO_FILE = "CallCenterPhoneCall.mp3" 21 | 22 | 23 | def main(): 24 | try: 25 | # STEP 1 Create a Deepgram client using the API key in the environment variables 26 | # config: DeepgramClientOptions = DeepgramClientOptions( 27 | # verbose=verboselogs.SPAM, 28 | # ) 29 | # deepgram: DeepgramClient = DeepgramClient("", config) 30 | # OR use defaults 31 | deepgram: DeepgramClient = DeepgramClient() 32 | 33 | # STEP 2 Call the transcribe_file method on the rest class 34 | with open(AUDIO_FILE, "rb") as file: 35 | buffer_data = file.read() 36 | 37 | payload: FileSource = { 38 | "buffer": buffer_data, 39 | } 40 | 41 | options: PrerecordedOptions = PrerecordedOptions( 42 | model="nova-3", 43 | smart_format=True, 44 | utterances=True, 45 | punctuate=True, 46 | summarize="v2", 47 | ) 48 | 49 | before = datetime.now() 50 | response = deepgram.listen.rest.v("1").transcribe_file(payload, options) 51 | after = datetime.now() 52 | 53 | print(response.to_json(indent=4)) 54 | print("") 55 | difference = after - before 56 | print(f"time: {difference.seconds}") 57 | 58 | except Exception as e: 59 | print(f"Exception: {e}") 60 | 61 | 62 | if __name__ == "__main__": 63 | main() 64 | -------------------------------------------------------------------------------- /examples/speech-to-text/rest/sync/file/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import os 6 | from dotenv import load_dotenv 7 | import logging 8 | from deepgram.utils import verboselogs 9 | from datetime import datetime 10 | import httpx 11 | 12 | from deepgram import ( 13 | DeepgramClient, 14 | DeepgramClientOptions, 15 | PrerecordedOptions, 16 | FileSource, 17 | ) 18 | 19 | load_dotenv() 20 | 21 | AUDIO_FILE = "preamble.wav" 22 | 23 | 24 | def main(): 25 | try: 26 | # STEP 1 Create a Deepgram client using the API key in the environment variables 27 | config: DeepgramClientOptions = DeepgramClientOptions( 28 | verbose=verboselogs.SPAM, 29 | ) 30 | deepgram: DeepgramClient = DeepgramClient("", config) 31 | # OR use defaults 32 | # deepgram: DeepgramClient = DeepgramClient() 33 | 34 | # STEP 2 Call the transcribe_file method on the rest class 35 | with open(AUDIO_FILE, "rb") as file: 36 | buffer_data = file.read() 37 | 38 | payload: FileSource = { 39 | "buffer": buffer_data, 40 | } 41 | 42 | options: PrerecordedOptions = PrerecordedOptions( 43 | model="nova-3", 44 | smart_format=True, 45 | utterances=True, 46 | punctuate=True, 47 | diarize=True, 48 | ) 49 | 50 | before = datetime.now() 51 | response = deepgram.listen.rest.v("1").transcribe_file( 52 | payload, options, timeout=httpx.Timeout(300.0, connect=10.0) 53 | ) 54 | after = datetime.now() 55 | 56 | print(response.to_json(indent=4)) 57 | print("") 58 | difference = after - before 59 | print(f"time: {difference.seconds}") 60 | 61 | except Exception as e: 62 | print(f"Exception: {e}") 63 | 64 | 65 | if __name__ == "__main__": 66 | main() 67 | -------------------------------------------------------------------------------- /examples/speech-to-text/rest/sync/file/preamble.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deepgram/deepgram-python-sdk/6380b56f810b31323aedf7b644c5a0466f48a1ee/examples/speech-to-text/rest/sync/file/preamble.wav -------------------------------------------------------------------------------- /examples/speech-to-text/rest/sync/url/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import os 6 | from dotenv import load_dotenv 7 | import logging 8 | from deepgram.utils import verboselogs 9 | from datetime import datetime 10 | import httpx 11 | 12 | from deepgram import ( 13 | DeepgramClient, 14 | DeepgramClientOptions, 15 | PrerecordedOptions, 16 | UrlSource, 17 | ) 18 | 19 | load_dotenv() 20 | 21 | # URL to the audio file to transcribe 22 | AUDIO_URL = "https://dpgr.am/spacewalk.wav" # Replace with your audio URL 23 | 24 | 25 | def main(): 26 | try: 27 | # STEP 1 Create a Deepgram client using the API key in the environment variables 28 | config: DeepgramClientOptions = DeepgramClientOptions( 29 | verbose=verboselogs.SPAM, 30 | ) 31 | deepgram: DeepgramClient = DeepgramClient("", config) 32 | # OR use defaults 33 | # deepgram: DeepgramClient = DeepgramClient() 34 | 35 | # STEP 2 Call the transcribe_url method on the rest class 36 | payload: UrlSource = { 37 | "url": AUDIO_URL, 38 | } 39 | 40 | options: PrerecordedOptions = PrerecordedOptions( 41 | model="nova-3", 42 | smart_format=True, 43 | ) 44 | 45 | before = datetime.now() 46 | response = deepgram.listen.rest.v("1").transcribe_url( 47 | payload, options, timeout=httpx.Timeout(300.0, connect=10.0) 48 | ) 49 | after = datetime.now() 50 | 51 | print(response.to_json(indent=4)) 52 | print("") 53 | difference = after - before 54 | print(f"time: {difference.seconds}") 55 | 56 | except Exception as e: 57 | print(f"Exception: {e}") 58 | 59 | 60 | if __name__ == "__main__": 61 | main() 62 | -------------------------------------------------------------------------------- /examples/speech-to-text/rest/topic/CallCenterPhoneCall.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deepgram/deepgram-python-sdk/6380b56f810b31323aedf7b644c5a0466f48a1ee/examples/speech-to-text/rest/topic/CallCenterPhoneCall.mp3 -------------------------------------------------------------------------------- /examples/speech-to-text/rest/topic/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import os 6 | from dotenv import load_dotenv 7 | import logging 8 | from deepgram.utils import verboselogs 9 | from datetime import datetime, timedelta 10 | 11 | from deepgram import ( 12 | DeepgramClient, 13 | ClientOptionsFromEnv, 14 | PrerecordedOptions, 15 | FileSource, 16 | ) 17 | 18 | load_dotenv() 19 | 20 | AUDIO_FILE = "CallCenterPhoneCall.mp3" 21 | 22 | 23 | def main(): 24 | try: 25 | # STEP 1 Create a Deepgram client using the API key in the environment variables 26 | # config: DeepgramClientOptions = DeepgramClientOptions( 27 | # verbose=verboselogs.SPAM, 28 | # ) 29 | # deepgram: DeepgramClient = DeepgramClient("", config) 30 | # OR use defaults 31 | deepgram: DeepgramClient = DeepgramClient() 32 | 33 | # STEP 2 Call the transcribe_file method on the rest class 34 | with open(AUDIO_FILE, "rb") as file: 35 | buffer_data = file.read() 36 | 37 | payload: FileSource = { 38 | "buffer": buffer_data, 39 | } 40 | 41 | options: PrerecordedOptions = PrerecordedOptions( 42 | model="nova-3", 43 | smart_format=True, 44 | utterances=True, 45 | punctuate=True, 46 | topics=True, 47 | ) 48 | 49 | before = datetime.now() 50 | response = deepgram.listen.rest.v("1").transcribe_file(payload, options) 51 | after = datetime.now() 52 | 53 | print(response.to_json(indent=4)) 54 | print("") 55 | difference = after - before 56 | print(f"time: {difference.seconds}") 57 | 58 | except Exception as e: 59 | print(f"Exception: {e}") 60 | 61 | 62 | if __name__ == "__main__": 63 | main() 64 | -------------------------------------------------------------------------------- /examples/speech-to-text/websocket/async_microphone/README.md: -------------------------------------------------------------------------------- 1 | # Live API (Real-Time) Example 2 | 3 | This example uses the Microphone to perform real-time transcription. This example required additional components (for the microphone) to be installed in order for this example to function correctly. 4 | 5 | ## Prerequisites 6 | 7 | This example will only work on Linux and macOS. Windows platforms are not supported. 8 | 9 | ## Configuration 10 | 11 | The SDK (and this example) needs to be initialized with your account's credentials `DEEPGRAM_API_KEY`, which are available in your [Deepgram Console][dg-console]. If you don't have a Deepgram account, you can [sign up here][dg-signup] for free. 12 | 13 | You must add your `DEEPGRAM_API_KEY` to your list of environment variables. We use environment variables because they are easy to configure, support PaaS-style deployments, and work well in containerized environments like Docker and Kubernetes. 14 | 15 | ```bash 16 | export DEEPGRAM_API_KEY=YOUR-APP-KEY-HERE 17 | ``` 18 | 19 | ## Installation 20 | 21 | The Live API (Real-Time) example makes use of a [microphone package](https://github.com/deepgram/deepgram-python-sdk/tree/main/deepgram/audio/microphone) contained within the repository. That package makes use of the [PortAudio library](http://www.portaudio.com/) which is a cross-platform open source audio library. If you are on Linux, you can install this library using whatever package manager is available (yum, apt, etc.) on your operating system. If you are on macOS, you can install this library using [brew](https://brew.sh/). 22 | 23 | [dg-console]: https://console.deepgram.com/ 24 | [dg-signup]: https://console.deepgram.com/signup 25 | -------------------------------------------------------------------------------- /examples/speech-to-text/websocket/legacy_dict_microphone/README.md: -------------------------------------------------------------------------------- 1 | # Live API (Real-Time) Example 2 | 3 | This example uses the Microphone to perform real-time transcription. This example required additional components (for the microphone) to be installed in order for this example to function correctly. 4 | 5 | ## Prerequisites 6 | 7 | This example will only work on Linux and macOS. Windows platforms are not supported. 8 | 9 | ## Configuration 10 | 11 | The SDK (and this example) needs to be initialized with your account's credentials `DEEPGRAM_API_KEY`, which are available in your [Deepgram Console][dg-console]. If you don't have a Deepgram account, you can [sign up here][dg-signup] for free. 12 | 13 | You must add your `DEEPGRAM_API_KEY` to your list of environment variables. We use environment variables because they are easy to configure, support PaaS-style deployments, and work well in containerized environments like Docker and Kubernetes. 14 | 15 | ```bash 16 | export DEEPGRAM_API_KEY=YOUR-APP-KEY-HERE 17 | ``` 18 | 19 | ## Installation 20 | 21 | The Live API (Real-Time) example makes use of a [microphone package](https://github.com/deepgram/deepgram-python-sdk/tree/main/deepgram/audio/microphone) contained within the repository. That package makes use of the [PortAudio library](http://www.portaudio.com/) which is a cross-platform open source audio library. If you are on Linux, you can install this library using whatever package manager is available (yum, apt, etc.) on your operating system. If you are on macOS, you can install this library using [brew](https://brew.sh/). 22 | 23 | [dg-console]: https://console.deepgram.com/ 24 | [dg-signup]: https://console.deepgram.com/signup 25 | -------------------------------------------------------------------------------- /examples/speech-to-text/websocket/microphone/README.md: -------------------------------------------------------------------------------- 1 | # Live API (Real-Time) Example 2 | 3 | This example uses the Microphone to perform real-time transcription. This example required additional components (for the microphone) to be installed in order for this example to function correctly. 4 | 5 | ## Prerequisites 6 | 7 | This example will only work on Linux and macOS. Windows platforms are not supported. 8 | 9 | ## Configuration 10 | 11 | The SDK (and this example) needs to be initialized with your account's credentials `DEEPGRAM_API_KEY`, which are available in your [Deepgram Console][dg-console]. If you don't have a Deepgram account, you can [sign up here][dg-signup] for free. 12 | 13 | You must add your `DEEPGRAM_API_KEY` to your list of environment variables. We use environment variables because they are easy to configure, support PaaS-style deployments, and work well in containerized environments like Docker and Kubernetes. 14 | 15 | ```bash 16 | export DEEPGRAM_API_KEY=YOUR-APP-KEY-HERE 17 | ``` 18 | 19 | ## Installation 20 | 21 | The Live API (Real-Time) example makes use of a [microphone package](https://github.com/deepgram/deepgram-python-sdk/tree/main/deepgram/audio/microphone) contained within the repository. That package makes use of the [PortAudio library](http://www.portaudio.com/) which is a cross-platform open source audio library. If you are on Linux, you can install this library using whatever package manager is available (yum, apt, etc.) on your operating system. If you are on macOS, you can install this library using [brew](https://brew.sh/). 22 | 23 | [dg-console]: https://console.deepgram.com/ 24 | [dg-signup]: https://console.deepgram.com/signup 25 | -------------------------------------------------------------------------------- /examples/speech-to-text/websocket/replay/microsoft_headquarters.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deepgram/deepgram-python-sdk/6380b56f810b31323aedf7b644c5a0466f48a1ee/examples/speech-to-text/websocket/replay/microsoft_headquarters.wav -------------------------------------------------------------------------------- /examples/text-to-speech/rest/file/async_hello_world/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import asyncio 6 | from dotenv import load_dotenv 7 | import logging 8 | from deepgram.utils import verboselogs 9 | 10 | from deepgram import ( 11 | DeepgramClient, 12 | ClientOptionsFromEnv, 13 | SpeakOptions, 14 | ) 15 | 16 | load_dotenv() 17 | 18 | SPEAK_TEXT = {"text": "Hello world!"} 19 | filename = "test.mp3" 20 | 21 | 22 | async def main(): 23 | try: 24 | # STEP 1 Create a Deepgram client using the API key from environment variables 25 | deepgram = DeepgramClient(api_key="", config=ClientOptionsFromEnv()) 26 | 27 | # STEP 2 Call the save method on the asyncspeak property 28 | options = SpeakOptions( 29 | model="aura-2-thalia-en", 30 | ) 31 | 32 | response = await deepgram.speak.asyncrest.v("1").save( 33 | filename, SPEAK_TEXT, options 34 | ) 35 | print(response.to_json(indent=4)) 36 | 37 | except Exception as e: 38 | print(f"Exception: {e}") 39 | 40 | 41 | if __name__ == "__main__": 42 | asyncio.run(main()) 43 | -------------------------------------------------------------------------------- /examples/text-to-speech/rest/file/hello_world/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import os 6 | from dotenv import load_dotenv 7 | import logging 8 | from deepgram.utils import verboselogs 9 | 10 | from deepgram import ( 11 | DeepgramClient, 12 | ClientOptionsFromEnv, 13 | SpeakOptions, 14 | ) 15 | 16 | load_dotenv() 17 | 18 | SPEAK_TEXT = {"text": "Hello world!"} 19 | filename = "test.mp3" 20 | 21 | 22 | def main(): 23 | try: 24 | # STEP 1 Create a Deepgram client using the API key from environment variables 25 | deepgram = DeepgramClient( 26 | api_key="", config=ClientOptionsFromEnv(verbose=verboselogs.SPAM) 27 | ) 28 | 29 | # STEP 2 Call the save method on the speak property 30 | options = SpeakOptions( 31 | model="aura-2-thalia-en", 32 | ) 33 | 34 | response = deepgram.speak.rest.v("1").save(filename, SPEAK_TEXT, options) 35 | print(response.to_json(indent=4)) 36 | 37 | except Exception as e: 38 | print(f"Exception: {e}") 39 | 40 | 41 | if __name__ == "__main__": 42 | main() 43 | -------------------------------------------------------------------------------- /examples/text-to-speech/rest/file/legacy_dict_hello_world/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import os 6 | from dotenv import load_dotenv 7 | import logging 8 | from deepgram.utils import verboselogs 9 | 10 | from deepgram import ( 11 | DeepgramClient, 12 | ClientOptionsFromEnv, 13 | SpeakOptions, 14 | ) 15 | 16 | load_dotenv() 17 | 18 | SPEAK_TEXT = {"text": "Hello world!"} 19 | filename = "test.mp3" 20 | 21 | 22 | def main(): 23 | try: 24 | # STEP 1 Create a Deepgram client using the API key from environment variables 25 | deepgram = DeepgramClient(api_key="", config=ClientOptionsFromEnv()) 26 | 27 | # STEP 2 Call the save method on the speak property 28 | options = { 29 | "model": "aura-2-thalia-en", 30 | } 31 | 32 | response = deepgram.speak.rest.v("1").save(filename, SPEAK_TEXT, options) 33 | print(response.to_json(indent=4)) 34 | 35 | except Exception as e: 36 | print(f"Exception: {e}") 37 | 38 | 39 | if __name__ == "__main__": 40 | main() 41 | -------------------------------------------------------------------------------- /examples/text-to-speech/rest/file/woodchuck/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import os 6 | from dotenv import load_dotenv 7 | import logging 8 | from deepgram.utils import verboselogs 9 | 10 | from deepgram import ( 11 | DeepgramClient, 12 | ClientOptionsFromEnv, 13 | SpeakOptions, 14 | ) 15 | 16 | load_dotenv() 17 | 18 | SPEAK_TEXT = { 19 | "text": "How much wood could a woodchuck chuck? If a woodchuck could chuck wood? As much wood as a woodchuck could chuck, if a woodchuck could chuck wood." 20 | } 21 | filename = "test.mp3" 22 | 23 | 24 | def main(): 25 | try: 26 | # STEP 1 Create a Deepgram client using the API key from environment variables 27 | deepgram = DeepgramClient(api_key="", config=ClientOptionsFromEnv()) 28 | 29 | # STEP 2 Call the save method on the speak property 30 | options = SpeakOptions( 31 | model="aura-2-thalia-en", 32 | ) 33 | 34 | response = deepgram.speak.rest.v("1").save(filename, SPEAK_TEXT, options) 35 | print(response.to_json(indent=4)) 36 | 37 | except Exception as e: 38 | print(f"Exception: {e}") 39 | 40 | 41 | if __name__ == "__main__": 42 | main() 43 | -------------------------------------------------------------------------------- /examples/text-to-speech/rest/memory/async_hello_world/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import asyncio, aiofiles 6 | from dotenv import load_dotenv 7 | import logging 8 | from deepgram.utils import verboselogs 9 | 10 | from deepgram import ( 11 | DeepgramClient, 12 | ClientOptionsFromEnv, 13 | SpeakOptions, 14 | ) 15 | 16 | load_dotenv() 17 | 18 | SPEAK_TEXT = {"text": "Hello world!"} 19 | filename = "test.mp3" 20 | 21 | 22 | async def main(): 23 | try: 24 | # STEP 1 Create a Deepgram client using the API key from environment variables 25 | deepgram = DeepgramClient(api_key="", config=ClientOptionsFromEnv()) 26 | 27 | # STEP 2 Call the save method on the asyncspeak property 28 | options = SpeakOptions( 29 | model="aura-2-thalia-en", 30 | ) 31 | 32 | response = await deepgram.speak.asyncrest.v("1").stream_memory( 33 | SPEAK_TEXT, options 34 | ) 35 | 36 | # save to file 37 | async with aiofiles.open(filename, "wb") as out: 38 | await out.write(response.stream_memory.getbuffer()) 39 | await out.flush() 40 | 41 | # file metadata 42 | print(response.to_json(indent=4)) 43 | 44 | except Exception as e: 45 | print(f"Exception: {e}") 46 | 47 | 48 | if __name__ == "__main__": 49 | asyncio.run(main()) 50 | -------------------------------------------------------------------------------- /examples/text-to-speech/rest/memory/hello_world/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import os 6 | from dotenv import load_dotenv 7 | import logging 8 | from deepgram.utils import verboselogs 9 | 10 | from deepgram import ( 11 | DeepgramClient, 12 | ClientOptionsFromEnv, 13 | SpeakOptions, 14 | ) 15 | 16 | load_dotenv() 17 | 18 | SPEAK_TEXT = {"text": "Hello world!"} 19 | filename = "test.mp3" 20 | 21 | 22 | def main(): 23 | try: 24 | # STEP 1 Create a Deepgram client using the API key from environment variables 25 | deepgram = DeepgramClient( 26 | api_key="", config=ClientOptionsFromEnv(verbose=verboselogs.SPAM) 27 | ) 28 | 29 | # STEP 2 Call the save method on the speak property 30 | options = SpeakOptions( 31 | model="aura-2-thalia-en", 32 | ) 33 | 34 | response = deepgram.speak.rest.v("1").stream_memory(SPEAK_TEXT, options) 35 | 36 | # save to file 37 | with open(filename, "wb+") as file: 38 | file.write(response.stream_memory.getbuffer()) 39 | file.flush() 40 | 41 | # file metadata 42 | print(response.to_json(indent=4)) 43 | 44 | except Exception as e: 45 | print(f"Exception: {e}") 46 | 47 | 48 | if __name__ == "__main__": 49 | main() 50 | -------------------------------------------------------------------------------- /examples/text-to-speech/rest/raw/async_hello_world/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import asyncio 6 | import aiofiles 7 | from dotenv import load_dotenv 8 | import logging 9 | from deepgram.utils import verboselogs 10 | 11 | from deepgram import ( 12 | DeepgramClient, 13 | DeepgramClientOptions, 14 | SpeakOptions, 15 | ) 16 | 17 | load_dotenv() 18 | 19 | SPEAK_TEXT = {"text": "Hello world!"} 20 | filename = "test.mp3" 21 | 22 | 23 | async def main(): 24 | try: 25 | # STEP 1 Create a Deepgram client using the API key from environment variables 26 | config: DeepgramClientOptions = DeepgramClientOptions( 27 | # verbose=verboselogs.SPAM, 28 | ) 29 | deepgram: DeepgramClient = DeepgramClient("", config) 30 | 31 | # STEP 2 Call the save method on the asyncspeak property 32 | options = SpeakOptions( 33 | model="aura-2-thalia-en", 34 | ) 35 | 36 | response = await deepgram.speak.asyncrest.v("1").stream_raw(SPEAK_TEXT, options) 37 | 38 | print(f"Response: {response}") 39 | for header in response.headers: 40 | print(f"{header}: {response.headers[header]}") 41 | async with aiofiles.open(filename, "wb") as out: 42 | async for data in response.aiter_bytes(): 43 | await out.write(data) 44 | await out.flush() 45 | await response.aclose() 46 | 47 | except Exception as e: 48 | print(f"Exception: {e}") 49 | 50 | 51 | if __name__ == "__main__": 52 | asyncio.run(main()) 53 | -------------------------------------------------------------------------------- /examples/text-to-speech/rest/raw/hello_world/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import os 6 | from dotenv import load_dotenv 7 | import logging 8 | from deepgram.utils import verboselogs 9 | 10 | from deepgram import ( 11 | DeepgramClient, 12 | DeepgramClientOptions, 13 | SpeakOptions, 14 | ) 15 | 16 | load_dotenv() 17 | 18 | SPEAK_TEXT = {"text": "Hello world!"} 19 | filename = "test.mp3" 20 | 21 | 22 | def main(): 23 | try: 24 | # STEP 1 Create a Deepgram client using the API key from environment variables 25 | config: DeepgramClientOptions = DeepgramClientOptions( 26 | # verbose=verboselogs.SPAM, 27 | ) 28 | deepgram: DeepgramClient = DeepgramClient("", config) 29 | 30 | # STEP 2 Call the save method on the speak property 31 | options = SpeakOptions( 32 | model="aura-2-thalia-en", 33 | ) 34 | 35 | response = deepgram.speak.rest.v("1").stream_raw(SPEAK_TEXT, options) 36 | 37 | for header in response.headers: 38 | print(f"{header}: {response.headers[header]}") 39 | with open(filename, "wb") as f: 40 | for data in response.iter_bytes(): 41 | f.write(data) 42 | response.close() 43 | 44 | except Exception as e: 45 | print(f"Exception: {e}") 46 | 47 | 48 | if __name__ == "__main__": 49 | main() 50 | -------------------------------------------------------------------------------- /hack/check/check-mdlint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 4 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 | # SPDX-License-Identifier: MIT 6 | 7 | set -o errexit 8 | set -o nounset 9 | set -o pipefail 10 | 11 | # Change directories to the parent directory of the one in which this 12 | # script is located. 13 | cd "$(dirname "${BASH_SOURCE[0]}")/../.." 14 | 15 | # mdlint rules with common errors and possible fixes can be found here: 16 | # https://github.com/igorshubovych/markdownlint-cli 17 | docker run -v "$PWD":/workdir \ 18 | ghcr.io/igorshubovych/markdownlint-cli:latest \ 19 | -i LICENSE \ 20 | "*.md" 21 | -------------------------------------------------------------------------------- /hack/check/check-shell.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 4 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 | # SPDX-License-Identifier: MIT 6 | 7 | set -o errexit 8 | set -o nounset 9 | set -o pipefail 10 | 11 | # Change directories to the parent directory of the one in which this 12 | # script is located. 13 | cd "$(dirname "${BASH_SOURCE[0]}")/../.." 14 | 15 | usage() { 16 | cat <&2; exit 1 29 | ;; 30 | \?) 31 | { echo "invalid option: -${OPTARG}"; usage; } 1>&2; exit 1 32 | ;; 33 | :) 34 | echo "option -${OPTARG} requires an argument" 1>&2; exit 1 35 | ;; 36 | esac 37 | done 38 | 39 | shellcheck --version 40 | find . -path ./vendor -prune -o -name "*.*sh" -type f -print0 | xargs -0 shellcheck 41 | -------------------------------------------------------------------------------- /hack/check/check-yaml.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 4 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 | # SPDX-License-Identifier: MIT 6 | 7 | set -o nounset 8 | set -o pipefail 9 | 10 | CHECK_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 11 | REPO_DIR="$(dirname "${CHECK_DIR}")/.." 12 | 13 | docker run --rm -t cytopia/yamllint --version 14 | CONTAINER_NAME="dg_yamllint_$RANDOM" 15 | docker run --name ${CONTAINER_NAME} -t -v "${REPO_DIR}":/deepgram-go-sdk:ro cytopia/yamllint -s -c /deepgram-go-sdk/.yamllintconfig.yaml /deepgram-go-sdk 16 | EXIT_CODE=$(docker inspect ${CONTAINER_NAME} --format='{{.State.ExitCode}}') 17 | docker rm -f ${CONTAINER_NAME} &> /dev/null 18 | 19 | if [[ ${EXIT_CODE} == "0" ]]; then 20 | echo "yamllint passed!" 21 | else 22 | echo "yamllint exit code ${EXIT_CODE}: YAML linting failed!" 23 | echo "Please fix the listed yamllint errors and verify using 'make yamllint'" 24 | exit "${EXIT_CODE}" 25 | fi 26 | -------------------------------------------------------------------------------- /hack/ensure-deps/ensure-actionlint.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 4 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 | # SPDX-License-Identifier: MIT 6 | 7 | set -o nounset 8 | set -o pipefail 9 | set -o xtrace 10 | 11 | CI_BUILD="${CI_BUILD:-""}" 12 | BUILD_OS=$(uname 2>/dev/null || echo Unknown) 13 | # BUILD_ARCH=$(uname -m 2>/dev/null || echo Unknown) 14 | ACTIONLINT_VERSION="1.6.27" 15 | 16 | SUDO_CMD="sudo" 17 | if [[ "${CI_BUILD}" == "true" ]]; then 18 | SUDO_CMD="" 19 | fi 20 | 21 | CMD="actionlint" 22 | if [[ -z "$(command -v ${CMD})" ]]; then 23 | echo "Attempting install of ${CMD}..." 24 | case "${BUILD_OS}" in 25 | Linux) 26 | curl -LO https://github.com/rhysd/actionlint/releases/download/v${ACTIONLINT_VERSION}/actionlint_${ACTIONLINT_VERSION}_linux_amd64.tar.gz 27 | mkdir actionlint_${ACTIONLINT_VERSION}_linux_amd64 28 | mv actionlint_${ACTIONLINT_VERSION}_linux_amd64.tar.gz ./actionlint_${ACTIONLINT_VERSION}_linux_amd64 29 | pushd "./actionlint_${ACTIONLINT_VERSION}_linux_amd64" || exit 1 30 | tar -xvf actionlint_${ACTIONLINT_VERSION}_linux_amd64.tar.gz 31 | chmod +x ${CMD} 32 | ${SUDO_CMD} install ./${CMD} /usr/local/bin 33 | popd || exit 1 34 | rm -rf ./actionlint_${ACTIONLINT_VERSION}_linux_amd64 35 | rm actionlint_${ACTIONLINT_VERSION}_linux_amd64.tar.gz 36 | ;; 37 | Darwin) 38 | brew install actionlint 39 | ;; 40 | esac 41 | fi 42 | -------------------------------------------------------------------------------- /hack/ensure-deps/ensure-dependencies.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 4 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 | # SPDX-License-Identifier: MIT 6 | 7 | # set -o errexit 8 | set -o nounset 9 | set -o pipefail 10 | set -o xtrace 11 | 12 | BUILD_OS=$(uname 2>/dev/null || echo Unknown) 13 | REPO_PATH="$(git rev-parse --show-toplevel)" 14 | 15 | case "${BUILD_OS}" in 16 | Linux) 17 | ;; 18 | Darwin) 19 | ;; 20 | *) 21 | echo "${BUILD_OS} is unsupported" 22 | exit 1 23 | ;; 24 | esac 25 | 26 | i=0 27 | 28 | # these are must have dependencies to just get going 29 | if [[ -z "$(command -v go)" ]]; then 30 | echo "Missing go" 31 | ((i=i+1)) 32 | fi 33 | if [[ -z "$(command -v docker)" ]]; then 34 | echo "Missing docker" 35 | ((i=i+1)) 36 | fi 37 | # these are must have dependencies to just get going 38 | 39 | if [[ $i -gt 0 ]]; then 40 | echo "Total missing: $i" 41 | echo "Please install these minimal dependencies in order to continue" 42 | exit 1 43 | fi 44 | 45 | "${REPO_PATH}/hack/ensure-deps/ensure-actionlint.sh" 46 | "${REPO_PATH}/hack/ensure-deps/ensure-shellcheck.sh" 47 | "${REPO_PATH}/hack/ensure-deps/ensure-diffutils.sh" 48 | "${REPO_PATH}/hack/ensure-deps/ensure-gh-cli.sh" 49 | "${REPO_PATH}/hack/ensure-deps/ensure-jq.sh" 50 | "${REPO_PATH}/hack/ensure-deps/ensure-portaudio.sh" 51 | 52 | echo "No missing dependencies!" 53 | -------------------------------------------------------------------------------- /hack/ensure-deps/ensure-diffutils.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 4 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 | # SPDX-License-Identifier: MIT 6 | 7 | set -o nounset 8 | set -o pipefail 9 | set -o xtrace 10 | 11 | _CI_BUILD="${_CI_BUILD:-""}" 12 | BUILD_OS=$(uname 2>/dev/null || echo Unknown) 13 | # BUILD_ARCH=$(uname -m 2>/dev/null || echo Unknown) 14 | # VERSION="1.7.1" 15 | 16 | SUDO_CMD="sudo" 17 | if [[ "${_CI_BUILD}" == "true" ]]; then 18 | SUDO_CMD="" 19 | fi 20 | 21 | CMD="diff3" 22 | if [[ -z "$(command -v ${CMD})" ]]; then 23 | echo "Attempting install of ${CMD}..." 24 | case "${BUILD_OS}" in 25 | Linux) 26 | if [[ -f "/etc/redhat-release" ]]; then 27 | ${SUDO_CMD} yum -y install diffutils 28 | elif [[ "$(grep Ubuntu /etc/os-release)" != "" ]]; then 29 | ${SUDO_CMD} apt-get -y install diffutils 30 | else 31 | echo "**** Please install diffutils before proceeding *****" 32 | exit 1 33 | fi 34 | ;; 35 | Darwin) 36 | brew install diffutils 37 | ;; 38 | esac 39 | fi 40 | -------------------------------------------------------------------------------- /hack/ensure-deps/ensure-gh-cli.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 4 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 | # SPDX-License-Identifier: MIT 6 | 7 | set -o nounset 8 | set -o pipefail 9 | set -o xtrace 10 | 11 | CI_BUILD="${CI_BUILD:-""}" 12 | BUILD_OS=$(uname 2>/dev/null || echo Unknown) 13 | # BUILD_ARCH=$(uname -m 2>/dev/null || echo Unknown) 14 | VERSION="2.48.0" 15 | 16 | SUDO_CMD="sudo" 17 | if [[ "${CI_BUILD}" == "true" ]]; then 18 | SUDO_CMD="" 19 | fi 20 | 21 | CMD="gh" 22 | if [[ -z "$(command -v ${CMD})" ]]; then 23 | echo "Attempting install of ${CMD}..." 24 | case "${BUILD_OS}" in 25 | Linux) 26 | curl -LO https://github.com/cli/cli/releases/download/v${VERSION}/gh_${VERSION}_linux_amd64.tar.gz 27 | tar -xvf gh_${VERSION}_linux_amd64.tar.gz 28 | pushd "./gh_${VERSION}_linux_amd64/bin" || exit 1 29 | chmod +x ${CMD} 30 | ${SUDO_CMD} install ./${CMD} /usr/local/bin 31 | popd || exit 1 32 | rm -rf ./gh_${VERSION}_linux_amd64 33 | rm gh_${VERSION}_linux_amd64.tar.gz 34 | ;; 35 | Darwin) 36 | brew install gh 37 | ;; 38 | esac 39 | fi 40 | -------------------------------------------------------------------------------- /hack/ensure-deps/ensure-jq.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 4 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 | # SPDX-License-Identifier: MIT 6 | 7 | set -o nounset 8 | set -o pipefail 9 | set -o xtrace 10 | 11 | _CI_BUILD="${_CI_BUILD:-""}" 12 | BUILD_OS=$(uname 2>/dev/null || echo Unknown) 13 | # BUILD_ARCH=$(uname -m 2>/dev/null || echo Unknown) 14 | VERSION="1.7.1" 15 | 16 | SUDO_CMD="sudo" 17 | if [[ "${_CI_BUILD}" == "true" ]]; then 18 | SUDO_CMD="" 19 | fi 20 | 21 | CMD="jq" 22 | if [[ -z "$(command -v ${CMD})" ]]; then 23 | echo "Attempting install of ${CMD}..." 24 | case "${BUILD_OS}" in 25 | Linux) 26 | curl -L "https://github.com/stedolan/jq/releases/download/jq-${VERSION}/jq-linux64" -o "jq" 27 | chmod +x jq 28 | ${SUDO_CMD} mv ${CMD} /usr/local/bin 29 | ;; 30 | Darwin) 31 | brew install jq 32 | ;; 33 | esac 34 | fi 35 | -------------------------------------------------------------------------------- /hack/ensure-deps/ensure-portaudio.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 4 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 | # SPDX-License-Identifier: MIT 6 | 7 | set -o nounset 8 | set -o pipefail 9 | set -o xtrace 10 | 11 | _CI_BUILD="${_CI_BUILD:-""}" 12 | BUILD_OS=$(uname 2>/dev/null || echo Unknown) 13 | # BUILD_ARCH=$(uname -m 2>/dev/null || echo Unknown) 14 | # VERSION="1.7.1" 15 | 16 | SUDO_CMD="sudo" 17 | if [[ "${_CI_BUILD}" == "true" ]]; then 18 | SUDO_CMD="" 19 | fi 20 | 21 | CMD="portaudio" 22 | if [[ -z "$(command -v ${CMD})" ]]; then 23 | echo "Attempting install of ${CMD}..." 24 | case "${BUILD_OS}" in 25 | Linux) 26 | if [[ -f "/etc/redhat-release" ]]; then 27 | ${SUDO_CMD} yum -y install portaudio19-dev 28 | elif [[ "$(grep Ubuntu /etc/os-release)" != "" ]]; then 29 | ${SUDO_CMD} apt-get -y install portaudio19-dev 30 | else 31 | echo "**** Please install portaudio before proceeding *****" 32 | exit 1 33 | fi 34 | ;; 35 | Darwin) 36 | brew install portaudio 37 | ;; 38 | esac 39 | fi 40 | -------------------------------------------------------------------------------- /hack/ensure-deps/ensure-shellcheck.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 4 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 | # SPDX-License-Identifier: MIT 6 | 7 | set -o nounset 8 | set -o pipefail 9 | set -o xtrace 10 | 11 | _CI_BUILD="${_CI_BUILD:-""}" 12 | BUILD_OS=$(uname 2>/dev/null || echo Unknown) 13 | # BUILD_ARCH=$(uname -m 2>/dev/null || echo Unknown) 14 | VERSION="0.10.0" 15 | 16 | SUDO_CMD="sudo" 17 | if [[ "${_CI_BUILD}" == "true" ]]; then 18 | SUDO_CMD="" 19 | fi 20 | 21 | CMD="shellcheck" 22 | if [[ -z "$(command -v ${CMD})" ]]; then 23 | echo "Attempting install of ${CMD}..." 24 | case "${BUILD_OS}" in 25 | Linux) 26 | curl -LO https://github.com/koalaman/shellcheck/releases/download/v${VERSION}/shellcheck-v${VERSION}.linux.x86_64.tar.xz 27 | tar -xvf shellcheck-v${VERSION}.linux.x86_64.tar.xz 28 | pushd "./shellcheck-v${VERSION}" || exit 1 29 | chmod +x ${CMD} 30 | ${SUDO_CMD} install ./${CMD} /usr/local/bin 31 | popd || exit 1 32 | rm -rf ./shellcheck-v${VERSION} 33 | rm shellcheck-v${VERSION}.linux.x86_64.tar.xz 34 | ;; 35 | Darwin) 36 | # case "${BUILD_ARCH}" in 37 | # x86_64) 38 | # brew install shellcheck 39 | # ;; 40 | # arm64) 41 | # brew install shellcheck 42 | # ;; 43 | # esac 44 | brew install shellcheck 45 | ;; 46 | esac 47 | fi 48 | -------------------------------------------------------------------------------- /mypy.ini: -------------------------------------------------------------------------------- 1 | # MyPy config file 2 | # File reference here - http://mypy.readthedocs.io/en/latest/config_file.html#config-file 3 | 4 | [mypy] 5 | warn_redundant_casts = True 6 | warn_unused_ignores = True 7 | 8 | # Needed because of bug in MyPy 9 | disallow_subclassing_any = False 10 | 11 | mypy_path = stubs 12 | 13 | [mypy-*] 14 | disallow_untyped_calls = True 15 | disallow_untyped_defs = True 16 | check_untyped_defs = True 17 | warn_return_any = True 18 | no_implicit_optional = True 19 | strict_optional = True 20 | ignore_missing_imports = True 21 | 22 | [mypy-setuptools] 23 | ignore_missing_imports = True 24 | 25 | [mypy-aenum] 26 | ignore_missing_imports = True 27 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | ###### 2 | # general configuration 3 | ###### 4 | [build-system] 5 | requires = ["setuptools", "wheel"] 6 | build-backend = "setuptools.build_meta" 7 | 8 | [project] 9 | name = "deepgram-sdk" 10 | dynamic = ["version", "description", "readme", "license", "authors", "keywords", "classifiers", "dependencies"] 11 | 12 | [tool.setuptools.dynamic] 13 | version = {attr = "deepgram.__version__"} 14 | 15 | ###### 16 | # poetry configuration 17 | ###### 18 | # [build-system] 19 | # requires = ["poetry-core"] 20 | # build-backend = "poetry.core.masonry.api" 21 | 22 | # poetry configuration 23 | [tool.poetry] 24 | name = "deepgram" 25 | version = "3.X.Y" # Please update this to the version you are using 26 | description = "The official Python SDK for the Deepgram automated speech recognition platform." 27 | authors = ["Deepgram DevRel "] 28 | license = "MIT" 29 | readme = "README.md" 30 | 31 | [tool.poetry.dependencies] 32 | python = "^3.10" 33 | httpx = "^0.25.2" 34 | websockets = ">=12.0" 35 | typing-extensions = "^4.9.0" 36 | dataclasses-json = "^0.6.3" 37 | aiohttp = "^3.9.1" 38 | aiofiles = "^23.2.1" 39 | aenum = "^3.1.0" 40 | deprecation = "^2.1.0" 41 | # needed only if you are looking to develop/work-on the SDK 42 | # black = "^24.0" 43 | # pylint = "^3.0" 44 | # mypy = "^1.0" 45 | # types-pyaudio = "^0.2.16" 46 | # types-aiofiles = "^23.2.0" 47 | # needed only if you are looking to use samples in the "examples" folder 48 | # pyaudio = "^0.2.14" 49 | # python-dotenv = "^1.0.0" 50 | # needed for contributing to the SDK 51 | # pytest-asyncio = "^0.21.1" 52 | # pytest = "^7.4.3" 53 | # fuzzywuzzy = "^0.18.0" 54 | # pytest-cov = "^4.1.0" 55 | 56 | # [tool.poetry.group.dev.dependencies] 57 | # fuzzywuzzy = "^0.18.0" 58 | -------------------------------------------------------------------------------- /requirements-dev.txt: -------------------------------------------------------------------------------- 1 | # pip install -r requirements.txt 2 | 3 | # additional requirements for development 4 | soundfile==0.12.1 5 | numpy==2.0.1 6 | websocket-server==0.6.4 7 | 8 | # lint, static, etc 9 | black==24.* 10 | pylint==3.* 11 | mypy==1.* 12 | 13 | # static check types 14 | types-pyaudio 15 | types-aiofiles 16 | 17 | # Testing 18 | pytest 19 | pytest-asyncio 20 | fuzzywuzzy 21 | pytest-cov -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | # pip install -r requirements.txt 2 | 3 | # standard libs 4 | websockets>=12.0 5 | httpx==0.* 6 | dataclasses-json==0.* 7 | dataclasses==0.* 8 | typing_extensions==4.* 9 | aenum==3.* 10 | deprecation==2.* 11 | 12 | # Async functionality, likely to be already installed 13 | aiohttp==3.* 14 | aiofiles==23.* 15 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from setuptools import setup, find_packages 6 | import os.path 7 | import sys 8 | 9 | if sys.version_info < (3, 10): 10 | sys.exit("Sorry, Python < 3.10 is not supported") 11 | 12 | with open("README.md", "r", encoding="utf-8") as fh: 13 | LONG_DESCRIPTION = fh.read() 14 | 15 | DESCRIPTION = ( 16 | "The official Python SDK for the Deepgram automated speech recognition platform." 17 | ) 18 | 19 | setup( 20 | name="deepgram-sdk", 21 | author="Deepgram", 22 | author_email="devrel@deepgram.com", 23 | url="https://github.com/deepgram/deepgram-python-sdk", 24 | description=DESCRIPTION, 25 | long_description=LONG_DESCRIPTION, 26 | long_description_content_type="text/markdown", 27 | license="MIT", 28 | packages=find_packages(exclude=["tests"]), 29 | install_requires=[ 30 | "httpx>=0.25.2", 31 | "websockets>=12.0", 32 | "dataclasses-json>=0.6.3", 33 | "typing_extensions>=4.9.0", 34 | "aiohttp>=3.9.1", 35 | "aiofiles>=23.2.1", 36 | "aenum>=3.1.0", 37 | "deprecation>=2.1.0", 38 | ], 39 | keywords=["deepgram", "deepgram speech-to-text"], 40 | classifiers=[ 41 | "Intended Audience :: Developers", 42 | "License :: OSI Approved :: MIT License", 43 | "Programming Language :: Python :: 3", 44 | ], 45 | ) 46 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from .utils import ( 6 | get_query_params, 7 | create_dirs, 8 | save_metadata_bytes, 9 | save_metadata_string, 10 | read_metadata_string, 11 | read_metadata_bytes, 12 | string_match_failure, 13 | ) 14 | -------------------------------------------------------------------------------- /tests/daily_test/preamble-rest.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deepgram/deepgram-python-sdk/6380b56f810b31323aedf7b644c5a0466f48a1ee/tests/daily_test/preamble-rest.wav -------------------------------------------------------------------------------- /tests/daily_test/preamble-websocket.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deepgram/deepgram-python-sdk/6380b56f810b31323aedf7b644c5a0466f48a1ee/tests/daily_test/preamble-websocket.wav -------------------------------------------------------------------------------- /tests/daily_test/testing-websocket.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deepgram/deepgram-python-sdk/6380b56f810b31323aedf7b644c5a0466f48a1ee/tests/daily_test/testing-websocket.wav -------------------------------------------------------------------------------- /tests/edge_cases/keepalive/async/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import asyncio 6 | import time 7 | import logging 8 | from deepgram.utils import verboselogs 9 | 10 | from deepgram import DeepgramClient, DeepgramClientOptions, LiveOptions 11 | 12 | 13 | async def main(): 14 | # for debugging 15 | config: DeepgramClientOptions = DeepgramClientOptions( 16 | verbose=verboselogs.DEBUG, options={"keepalive": "true"} 17 | ) 18 | deepgram: DeepgramClient = DeepgramClient("", config) 19 | 20 | deepgram_connection = deepgram.listen.asynclive.v("1") 21 | 22 | await deepgram_connection.start(LiveOptions()) 23 | 24 | # Wait for a while to simulate a long-running connection 25 | await asyncio.sleep(600) 26 | 27 | print("deadlock!") 28 | try: 29 | await deepgram_connection.finish() 30 | finally: 31 | print("no deadlock...") 32 | 33 | 34 | asyncio.run(main()) 35 | -------------------------------------------------------------------------------- /tests/edge_cases/keepalive/sync/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import time 6 | import logging 7 | from deepgram.utils import verboselogs 8 | 9 | from deepgram import DeepgramClient, DeepgramClientOptions, LiveOptions 10 | 11 | 12 | def main(): 13 | # for debugging 14 | config: DeepgramClientOptions = DeepgramClientOptions( 15 | verbose=verboselogs.DEBUG, options={"keepalive": "true"} 16 | ) 17 | deepgram: DeepgramClient = DeepgramClient("", config) 18 | # OR 19 | # deepgram: DeepgramClient = DeepgramClient() 20 | 21 | deepgram_connection = deepgram.listen.live.v("1") 22 | 23 | deepgram_connection.start(LiveOptions()) 24 | 25 | # press any key to exit 26 | input("\n\nPress Enter to exit...\n\n") 27 | 28 | print("deadlock!") 29 | try: 30 | deepgram_connection.finish() 31 | finally: 32 | print("no deadlock...") 33 | 34 | 35 | if __name__ == "__main__": 36 | main() 37 | -------------------------------------------------------------------------------- /tests/edge_cases/reconnect_same_object/sync/main.py: -------------------------------------------------------------------------------- 1 | import time 2 | import logging 3 | from deepgram.utils import verboselogs 4 | 5 | from deepgram import DeepgramClient, DeepgramClientOptions, LiveOptions, Microphone 6 | 7 | 8 | def main(): 9 | config: DeepgramClientOptions = DeepgramClientOptions(verbose=verboselogs.DEBUG) 10 | # config: DeepgramClientOptions = DeepgramClientOptions() 11 | deepgram: DeepgramClient = DeepgramClient("", config) 12 | options: LiveOptions = LiveOptions( 13 | model="nova-3", 14 | language="en-US", 15 | encoding="linear16", 16 | channels=1, 17 | sample_rate=16000, 18 | ) 19 | 20 | dg_connection = deepgram.listen.live.v("1") 21 | 22 | for x in range(0, 10): 23 | if x > 0: 24 | # wait for the connection to close 25 | time.sleep(5) 26 | 27 | if x == 0: 28 | print(f"Starting connection #{x}...") 29 | else: 30 | print(f"Restarting connection #{x}...") 31 | 32 | if dg_connection.start(options) is False: 33 | print("Failed to connect to Deepgram") 34 | continue 35 | 36 | microphone = Microphone(dg_connection.send) 37 | microphone.start() 38 | 39 | time.sleep(15) 40 | 41 | print("Calling stop...") 42 | microphone.finish() 43 | dg_connection.finish() 44 | 45 | print("Finished") 46 | 47 | 48 | if __name__ == "__main__": 49 | main() 50 | -------------------------------------------------------------------------------- /tests/expected_failures/exercise_timeout/async/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import asyncio 6 | import time 7 | import logging 8 | from deepgram.utils import verboselogs 9 | 10 | from deepgram import DeepgramClient, DeepgramClientOptions, LiveOptions 11 | 12 | 13 | async def main(): 14 | # for debugging 15 | config: DeepgramClientOptions = DeepgramClientOptions(verbose=verboselogs.DEBUG) 16 | deepgram: DeepgramClient = DeepgramClient("", config) 17 | # OR 18 | # deepgram: DeepgramClient = DeepgramClient() 19 | 20 | deepgram_connection = deepgram.listen.asynclive.v("1") 21 | 22 | await deepgram_connection.start(LiveOptions()) 23 | 24 | # Deepgram will close the connection after 10-15s of silence, followed with another 5 seconds for a ping 25 | await asyncio.sleep(30) 26 | 27 | print("deadlock!") 28 | try: 29 | await deepgram_connection.finish() 30 | finally: 31 | print("no deadlock...") 32 | 33 | 34 | asyncio.run(main()) 35 | -------------------------------------------------------------------------------- /tests/expected_failures/exercise_timeout/sync/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import time 6 | import logging 7 | from deepgram.utils import verboselogs 8 | 9 | from deepgram import DeepgramClient, DeepgramClientOptions, LiveOptions 10 | 11 | 12 | def main(): 13 | # for debugging 14 | config: DeepgramClientOptions = DeepgramClientOptions(verbose=verboselogs.SPAM) 15 | deepgram: DeepgramClient = DeepgramClient("", config) 16 | # OR 17 | # deepgram: DeepgramClient = DeepgramClient() 18 | 19 | deepgram_connection = deepgram.listen.live.v("1") 20 | 21 | deepgram_connection.start(LiveOptions()) 22 | 23 | # Deepgram will close the connection after 10-15s of silence, followed with another 5 seconds for a ping 24 | time.sleep(30) 25 | 26 | print("deadlock!") 27 | try: 28 | deepgram_connection.finish() 29 | finally: 30 | print("no deadlock...") 31 | 32 | 33 | if __name__ == "__main__": 34 | main() 35 | -------------------------------------------------------------------------------- /tests/response_data/listen/rest/a231370d439312b1a404bb6ad8de955e900ec8eae9a906329af8cc672e6ec7ba-29e7c8100617f70da4ae9da1921cb5071a01219f4780ca70930b0a370ed2163a-options.json: -------------------------------------------------------------------------------- 1 | {"model": "nova-3", "smart_format": true, "summarize": "v2"} -------------------------------------------------------------------------------- /tests/response_data/listen/rest/a231370d439312b1a404bb6ad8de955e900ec8eae9a906329af8cc672e6ec7ba-29e7c8100617f70da4ae9da1921cb5071a01219f4780ca70930b0a370ed2163a.cmd: -------------------------------------------------------------------------------- 1 | {"url": "https://static.deepgram.com/examples/Bueller-Life-moves-pretty-fast.wav"} -------------------------------------------------------------------------------- /tests/response_data/listen/rest/a231370d439312b1a404bb6ad8de955e900ec8eae9a906329af8cc672e6ec7ba-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76-error.json: -------------------------------------------------------------------------------- 1 | {"actual": "Speaker 1 discusses the goal of establishing a more perfect union, justice, and the common defense for the United States of America, as part of the Better Union movement.", "expected": ["*"]} -------------------------------------------------------------------------------- /tests/response_data/listen/rest/a231370d439312b1a404bb6ad8de955e900ec8eae9a906329af8cc672e6ec7ba-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76-options.json: -------------------------------------------------------------------------------- 1 | {"model": "nova-3", "smart_format": true, "summarize": "v2"} -------------------------------------------------------------------------------- /tests/response_data/listen/rest/a231370d439312b1a404bb6ad8de955e900ec8eae9a906329af8cc672e6ec7ba-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76.cmd: -------------------------------------------------------------------------------- 1 | "preamble-rest.wav" -------------------------------------------------------------------------------- /tests/response_data/listen/rest/b00dc103a62ea2ccfc752ec0f646c7528ef5e729a9d7481d2a944253a9128ce2-29e7c8100617f70da4ae9da1921cb5071a01219f4780ca70930b0a370ed2163a-options.json: -------------------------------------------------------------------------------- 1 | { 2 | "model": "nova-3", 3 | "smart_format": true 4 | } -------------------------------------------------------------------------------- /tests/response_data/listen/rest/b00dc103a62ea2ccfc752ec0f646c7528ef5e729a9d7481d2a944253a9128ce2-29e7c8100617f70da4ae9da1921cb5071a01219f4780ca70930b0a370ed2163a.cmd: -------------------------------------------------------------------------------- 1 | {"url": "https://static.deepgram.com/examples/Bueller-Life-moves-pretty-fast.wav"} -------------------------------------------------------------------------------- /tests/response_data/listen/rest/b00dc103a62ea2ccfc752ec0f646c7528ef5e729a9d7481d2a944253a9128ce2-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76-options.json: -------------------------------------------------------------------------------- 1 | { 2 | "model": "nova-3", 3 | "smart_format": true 4 | } -------------------------------------------------------------------------------- /tests/response_data/listen/rest/b00dc103a62ea2ccfc752ec0f646c7528ef5e729a9d7481d2a944253a9128ce2-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76.cmd: -------------------------------------------------------------------------------- 1 | "preamble-rest.wav" -------------------------------------------------------------------------------- /tests/response_data/listen/rest/c4e1c0031174878d8f0e3dbd87916ee16d56f1c610ac525af5712ea37226a455-29e7c8100617f70da4ae9da1921cb5071a01219f4780ca70930b0a370ed2163a-options.json: -------------------------------------------------------------------------------- 1 | {"model": "nova-3", "smart_format": true} -------------------------------------------------------------------------------- /tests/response_data/listen/rest/c4e1c0031174878d8f0e3dbd87916ee16d56f1c610ac525af5712ea37226a455-29e7c8100617f70da4ae9da1921cb5071a01219f4780ca70930b0a370ed2163a.cmd: -------------------------------------------------------------------------------- 1 | {"url": "https://static.deepgram.com/examples/Bueller-Life-moves-pretty-fast.wav"} -------------------------------------------------------------------------------- /tests/response_data/listen/rest/c4e1c0031174878d8f0e3dbd87916ee16d56f1c610ac525af5712ea37226a455-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76-error.json: -------------------------------------------------------------------------------- 1 | {"actual": "We, the people of The United States, in order to form a more perfect union, establish justice, ensure domestic tranquility, provide for the common defense, promote the general welfare, and secure the blessings of liberty to ourselves and our posterity to ordain and establish this constitution for The United States Of America.", "expected": ["We, the people of the United States, in order to form a more perfect union, establish justice, ensure domestic tranquility, provide for the common defense, promote the general welfare, and secure the blessings of liberty to ourselves and our posterity to ordain and establish this constitution for the United States of America."]} -------------------------------------------------------------------------------- /tests/response_data/listen/rest/c4e1c0031174878d8f0e3dbd87916ee16d56f1c610ac525af5712ea37226a455-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76-options.json: -------------------------------------------------------------------------------- 1 | {"model": "nova-3", "smart_format": true} -------------------------------------------------------------------------------- /tests/response_data/listen/rest/c4e1c0031174878d8f0e3dbd87916ee16d56f1c610ac525af5712ea37226a455-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76.cmd: -------------------------------------------------------------------------------- 1 | "preamble-rest.wav" -------------------------------------------------------------------------------- /tests/response_data/listen/rest/f3b6208a662156067a41bddd295a1a0a53ea34a268e27a8f1a9d7107aa99732f-29e7c8100617f70da4ae9da1921cb5071a01219f4780ca70930b0a370ed2163a-options.json: -------------------------------------------------------------------------------- 1 | { 2 | "model": "nova-3", 3 | "smart_format": true, 4 | "summarize": "v2" 5 | } -------------------------------------------------------------------------------- /tests/response_data/listen/rest/f3b6208a662156067a41bddd295a1a0a53ea34a268e27a8f1a9d7107aa99732f-29e7c8100617f70da4ae9da1921cb5071a01219f4780ca70930b0a370ed2163a.cmd: -------------------------------------------------------------------------------- 1 | {"url": "https://static.deepgram.com/examples/Bueller-Life-moves-pretty-fast.wav"} -------------------------------------------------------------------------------- /tests/response_data/listen/rest/f3b6208a662156067a41bddd295a1a0a53ea34a268e27a8f1a9d7107aa99732f-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76-error.json: -------------------------------------------------------------------------------- 1 | {"actual": "Speaker 1 discusses the goal of establishing a more perfect union, justice, and the common defense for the United States, as part of the Better Union movement. They emphasize the importance of these factors in securing the benefits of liberty for the United States and the world.", "expected": ["*"]} -------------------------------------------------------------------------------- /tests/response_data/listen/rest/f3b6208a662156067a41bddd295a1a0a53ea34a268e27a8f1a9d7107aa99732f-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76-options.json: -------------------------------------------------------------------------------- 1 | { 2 | "model": "nova-3", 3 | "smart_format": true, 4 | "summarize": "v2" 5 | } -------------------------------------------------------------------------------- /tests/response_data/listen/rest/f3b6208a662156067a41bddd295a1a0a53ea34a268e27a8f1a9d7107aa99732f-a17f4880c5b4cf124ac54d06d77c9f0ab7f3fe1052ff1c7b090f7eaf8ede5b76.cmd: -------------------------------------------------------------------------------- 1 | "preamble-rest.wav" -------------------------------------------------------------------------------- /tests/response_data/listen/websocket/a6d1b12d5ce73a51a7b69ab156f0c98c72cdc1cfcf4a25f7b634c328cce4d760-42fc5ed98cabc1fa1a2f276301c27c46dd15f6f5187cd93d944cc94fa81c8469-options.json: -------------------------------------------------------------------------------- 1 | { 2 | "channels": 1, 3 | "encoding": "mulaw", 4 | "language": "en-US", 5 | "model": "nova-3", 6 | "punctuate": true, 7 | "sample_rate": 8000, 8 | "smart_format": true 9 | } -------------------------------------------------------------------------------- /tests/response_data/listen/websocket/a6d1b12d5ce73a51a7b69ab156f0c98c72cdc1cfcf4a25f7b634c328cce4d760-42fc5ed98cabc1fa1a2f276301c27c46dd15f6f5187cd93d944cc94fa81c8469-response.json: -------------------------------------------------------------------------------- 1 | { 2 | "channel": { 3 | "alternatives": [ 4 | { 5 | "transcript": "For the United States of America.", 6 | "confidence": 0.9990865, 7 | "words": [ 8 | { 9 | "word": "for", 10 | "start": 17.56, 11 | "end": 17.72, 12 | "confidence": 0.9873626, 13 | "punctuated_word": "For" 14 | }, 15 | { 16 | "word": "the", 17 | "start": 17.72, 18 | "end": 17.88, 19 | "confidence": 0.9990865, 20 | "punctuated_word": "the" 21 | }, 22 | { 23 | "word": "united", 24 | "start": 17.88, 25 | "end": 17.96, 26 | "confidence": 0.99964666, 27 | "punctuated_word": "United" 28 | }, 29 | { 30 | "word": "states", 31 | "start": 17.96, 32 | "end": 18.12, 33 | "confidence": 0.9992742, 34 | "punctuated_word": "States" 35 | }, 36 | { 37 | "word": "of", 38 | "start": 18.12, 39 | "end": 18.2, 40 | "confidence": 0.99879324, 41 | "punctuated_word": "of" 42 | }, 43 | { 44 | "word": "america", 45 | "start": 18.2, 46 | "end": 18.66, 47 | "confidence": 0.96024, 48 | "punctuated_word": "America." 49 | } 50 | ] 51 | } 52 | ] 53 | }, 54 | "metadata": { 55 | "model_info": { 56 | "name": "2-general-nova", 57 | "version": "2024-01-18.26916", 58 | "arch": "nova-3" 59 | }, 60 | "request_id": "e1985d01-b8bc-42ab-a16a-e7a8419c07f2", 61 | "model_uuid": "c0d1a568-ce81-4fea-97e7-bd45cb1fdf3c" 62 | }, 63 | "type": "Results", 64 | "channel_index": [ 65 | 0, 66 | 1 67 | ], 68 | "duration": 1.6599998, 69 | "start": 17.0, 70 | "is_final": true, 71 | "from_finalize": false, 72 | "speech_final": true 73 | } -------------------------------------------------------------------------------- /tests/response_data/listen/websocket/a6d1b12d5ce73a51a7b69ab156f0c98c72cdc1cfcf4a25f7b634c328cce4d760-42fc5ed98cabc1fa1a2f276301c27c46dd15f6f5187cd93d944cc94fa81c8469.cmd: -------------------------------------------------------------------------------- 1 | "preamble-websocket.wav" -------------------------------------------------------------------------------- /tests/response_data/listen/websocket/a6d1b12d5ce73a51a7b69ab156f0c98c72cdc1cfcf4a25f7b634c328cce4d760-d7334c26cf6468c191e05ff5e8151da9b67985c66ab177e9446fd14bbafd70df-options.json: -------------------------------------------------------------------------------- 1 | { 2 | "channels": 1, 3 | "encoding": "mulaw", 4 | "language": "en-US", 5 | "model": "nova-3", 6 | "punctuate": true, 7 | "sample_rate": 8000, 8 | "smart_format": true 9 | } -------------------------------------------------------------------------------- /tests/response_data/listen/websocket/a6d1b12d5ce73a51a7b69ab156f0c98c72cdc1cfcf4a25f7b634c328cce4d760-d7334c26cf6468c191e05ff5e8151da9b67985c66ab177e9446fd14bbafd70df-response.json: -------------------------------------------------------------------------------- 1 | { 2 | "channel": { 3 | "alternatives": [ 4 | { 5 | "transcript": "Testing. 123. Testing. 123.", 6 | "confidence": 0.987885, 7 | "words": [ 8 | { 9 | "word": "testing", 10 | "start": 1.22, 11 | "end": 1.62, 12 | "confidence": 0.483064, 13 | "punctuated_word": "Testing." 14 | }, 15 | { 16 | "word": "123", 17 | "start": 1.62, 18 | "end": 2.12, 19 | "confidence": 0.93632686, 20 | "punctuated_word": "123." 21 | }, 22 | { 23 | "word": "testing", 24 | "start": 2.1799998, 25 | "end": 2.6799998, 26 | "confidence": 0.987885, 27 | "punctuated_word": "Testing." 28 | }, 29 | { 30 | "word": "123", 31 | "start": 3.1399999, 32 | "end": 3.6399999, 33 | "confidence": 0.99418044, 34 | "punctuated_word": "123." 35 | } 36 | ] 37 | } 38 | ] 39 | }, 40 | "metadata": { 41 | "model_info": { 42 | "name": "2-general-nova", 43 | "version": "2024-01-18.26916", 44 | "arch": "nova-3" 45 | }, 46 | "request_id": "26dd8cc9-77e6-4db7-a0ae-3034c013cb64", 47 | "model_uuid": "c0d1a568-ce81-4fea-97e7-bd45cb1fdf3c" 48 | }, 49 | "type": "Results", 50 | "channel_index": [ 51 | 0, 52 | 1 53 | ], 54 | "duration": 3.08, 55 | "start": 0.74, 56 | "is_final": true, 57 | "from_finalize": false, 58 | "speech_final": true 59 | } -------------------------------------------------------------------------------- /tests/response_data/listen/websocket/a6d1b12d5ce73a51a7b69ab156f0c98c72cdc1cfcf4a25f7b634c328cce4d760-d7334c26cf6468c191e05ff5e8151da9b67985c66ab177e9446fd14bbafd70df.cmd: -------------------------------------------------------------------------------- 1 | "testing-websocket.wav" -------------------------------------------------------------------------------- /tests/response_data/read/rest/3917a1c81c08e360c0d4bba0ff9ebd645e610e4149483e5f2888a2c5df388b37-23e873efdfd4d680286fda14ff8f10864218311e79efc92ecc82bce3e574c366-error.json: -------------------------------------------------------------------------------- 1 | {"actual": "The potential for voice-based interfaces in conversational AI applications is discussed, with a focus on voice-premised and wearable devices. The speakers emphasize the benefits of voice quality, including natural speech flow, and the potential for AI to be more human than humans in speech recognition. They also mention their involvement in machine learning and their plans to expand their waitlist for a speech-to-text model. They expect to release generally early next year, but if working on any real-time AI agent use cases, they can join their waitlist to jumpstart their development in production.", "expected": ["*"]} -------------------------------------------------------------------------------- /tests/response_data/read/rest/3917a1c81c08e360c0d4bba0ff9ebd645e610e4149483e5f2888a2c5df388b37-23e873efdfd4d680286fda14ff8f10864218311e79efc92ecc82bce3e574c366-options.json: -------------------------------------------------------------------------------- 1 | {"language": "en", "summarize": true} -------------------------------------------------------------------------------- /tests/response_data/read/rest/3917a1c81c08e360c0d4bba0ff9ebd645e610e4149483e5f2888a2c5df388b37-23e873efdfd4d680286fda14ff8f10864218311e79efc92ecc82bce3e574c366-response.json: -------------------------------------------------------------------------------- 1 | {"metadata": {"request_id": "c4bba0ce-f169-4618-a892-1a937aa83f45", "created": "2025-05-09T20:14:15.836Z", "language": "en", "summary_info": {"model_uuid": "67875a7f-c9c4-48a0-aa55-5bdb8a91c34a", "input_tokens": 1855, "output_tokens": 113}}, "results": {"summary": {"text": "The potential for voice-based interfaces in conversational AI applications is discussed, with a focus on voice-premised and wearable devices. The speakers emphasize the benefits of voice quality, including natural speech flow, and the potential for AI to be more human than humans in speech recognition. They also mention their involvement in machine learning and their plans to expand their waitlist for a speech-to-text model. They expect to release generally early next year, but if working on any real-time AI agent use cases, they can join their waitlist to jumpstart their development in production."}}} -------------------------------------------------------------------------------- /tests/response_data/read/rest/3917a1c81c08e360c0d4bba0ff9ebd645e610e4149483e5f2888a2c5df388b37-23e873efdfd4d680286fda14ff8f10864218311e79efc92ecc82bce3e574c366.cmd: -------------------------------------------------------------------------------- 1 | "conversation.txt" -------------------------------------------------------------------------------- /tests/response_data/speak/rest/18144fa7f4709bc9972c24d0addc8faa360dca933e7e0027b062e57b7c41f426-f8c3bf62a9aa3e6fc1619c250e48abe7519373d3edf41be62eb5dc45199af2ef-options.json: -------------------------------------------------------------------------------- 1 | {"model": "aura-2-thalia-en", "encoding": "linear16", "sample_rate": 24000} -------------------------------------------------------------------------------- /tests/response_data/speak/rest/18144fa7f4709bc9972c24d0addc8faa360dca933e7e0027b062e57b7c41f426-f8c3bf62a9aa3e6fc1619c250e48abe7519373d3edf41be62eb5dc45199af2ef-response.json: -------------------------------------------------------------------------------- 1 | {"content_type": "audio/wav", "request_id": "807aa4a7-8068-4d09-b6db-c99de6f436ee", "model_uuid": "ecb76e9d-f2db-4127-8060-79b05590d22f", "model_name": "aura-2-thalia-en", "characters": 13, "transfer_encoding": "chunked", "date": "Fri, 07 Feb 2025 01:53:41 GMT"} -------------------------------------------------------------------------------- /tests/response_data/speak/rest/18144fa7f4709bc9972c24d0addc8faa360dca933e7e0027b062e57b7c41f426-f8c3bf62a9aa3e6fc1619c250e48abe7519373d3edf41be62eb5dc45199af2ef.cmd: -------------------------------------------------------------------------------- 1 | Hello, world. -------------------------------------------------------------------------------- /tests/response_data/speak/rest/18144fa7f4709bc9972c24d0addc8faa360dca933e7e0027b062e57b7c41f426-f8c3bf62a9aa3e6fc1619c250e48abe7519373d3edf41be62eb5dc45199af2ef.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deepgram/deepgram-python-sdk/6380b56f810b31323aedf7b644c5a0466f48a1ee/tests/response_data/speak/rest/18144fa7f4709bc9972c24d0addc8faa360dca933e7e0027b062e57b7c41f426-f8c3bf62a9aa3e6fc1619c250e48abe7519373d3edf41be62eb5dc45199af2ef.wav -------------------------------------------------------------------------------- /tests/response_data/speak/rest/1fe0ad339338a9d6cffbab2c7ace41ba5387b5fe7906854795702dce91034fd3-f8c3bf62a9aa3e6fc1619c250e48abe7519373d3edf41be62eb5dc45199af2ef-options.json: -------------------------------------------------------------------------------- 1 | {"model": "aura-2-thalia-en", "encoding": "linear16", "sample_rate": 24000} -------------------------------------------------------------------------------- /tests/response_data/speak/rest/1fe0ad339338a9d6cffbab2c7ace41ba5387b5fe7906854795702dce91034fd3-f8c3bf62a9aa3e6fc1619c250e48abe7519373d3edf41be62eb5dc45199af2ef-response.json: -------------------------------------------------------------------------------- 1 | {"content_type": "audio/wav", "request_id": "2c6a0b36-dd43-4a67-be8a-721ae4a9f38d", "model_uuid": "0bb159e1-5c0a-48fb-aa29-ed7c0401f116", "model_name": "aura-2-thalia-en", "characters": 13, "transfer_encoding": "chunked", "date": "Fri, 09 May 2025 20:14:16 GMT"} -------------------------------------------------------------------------------- /tests/response_data/speak/rest/1fe0ad339338a9d6cffbab2c7ace41ba5387b5fe7906854795702dce91034fd3-f8c3bf62a9aa3e6fc1619c250e48abe7519373d3edf41be62eb5dc45199af2ef.cmd: -------------------------------------------------------------------------------- 1 | Hello, world. -------------------------------------------------------------------------------- /tests/response_data/speak/rest/1fe0ad339338a9d6cffbab2c7ace41ba5387b5fe7906854795702dce91034fd3-f8c3bf62a9aa3e6fc1619c250e48abe7519373d3edf41be62eb5dc45199af2ef.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deepgram/deepgram-python-sdk/6380b56f810b31323aedf7b644c5a0466f48a1ee/tests/response_data/speak/rest/1fe0ad339338a9d6cffbab2c7ace41ba5387b5fe7906854795702dce91034fd3-f8c3bf62a9aa3e6fc1619c250e48abe7519373d3edf41be62eb5dc45199af2ef.wav -------------------------------------------------------------------------------- /tests/unit_test/preamble-rest.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deepgram/deepgram-python-sdk/6380b56f810b31323aedf7b644c5a0466f48a1ee/tests/unit_test/preamble-rest.wav -------------------------------------------------------------------------------- /tests/unit_test/preamble-websocket.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deepgram/deepgram-python-sdk/6380b56f810b31323aedf7b644c5a0466f48a1ee/tests/unit_test/preamble-websocket.wav -------------------------------------------------------------------------------- /tests/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | from .utils import ( 6 | get_query_params, 7 | create_dirs, 8 | save_metadata_bytes, 9 | save_metadata_string, 10 | read_metadata_string, 11 | read_metadata_bytes, 12 | string_match_failure, 13 | ) 14 | -------------------------------------------------------------------------------- /tests/utils/test_utils.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import pytest 6 | 7 | from .utils import ( 8 | get_query_params, 9 | create_dirs, 10 | save_metadata_bytes, 11 | save_metadata_string, 12 | read_metadata_string, 13 | read_metadata_bytes, 14 | string_match_failure, 15 | ) 16 | 17 | 18 | def test_get_query_params(): 19 | assert get_query_params("http://example.com/path?name=test") == "name=test" 20 | assert get_query_params("http://example.com/path") == "" 21 | 22 | 23 | def test_create_dirs(tmp_path): 24 | test_dir = tmp_path / "test_dir" 25 | test_file = test_dir / "test_file.txt" 26 | create_dirs(test_file) 27 | assert test_dir.exists() 28 | 29 | 30 | def test_save_and_read_metadata_string(tmp_path): 31 | test_file = tmp_path / "test_file.txt" 32 | test_data = "test_data" 33 | save_metadata_string(test_file, test_data) 34 | assert read_metadata_string(test_file) == test_data 35 | 36 | 37 | def test_save_and_read_metadata_bytes(tmp_path): 38 | test_file = tmp_path / "test_file.txt" 39 | test_data = b"test_data" 40 | save_metadata_bytes(test_file, test_data) 41 | assert read_metadata_bytes(test_file) == test_data 42 | 43 | 44 | def test_string_match_failure(): 45 | expected = "expected" 46 | actual = "exzected" 47 | with pytest.raises(ValueError): 48 | string_match_failure(expected, actual) 49 | -------------------------------------------------------------------------------- /tests/utils/utils.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2 | # Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3 | # SPDX-License-Identifier: MIT 4 | 5 | import os 6 | 7 | 8 | def get_query_params(url: str) -> str: 9 | pos = url.find("?") 10 | if pos == -1: 11 | return "" 12 | return url[pos + 1 :] 13 | 14 | 15 | def create_dirs(fullpath: str) -> None: 16 | basedir = os.path.dirname(fullpath) 17 | os.makedirs(basedir, mode=0o700, exist_ok=True) 18 | 19 | 20 | def save_metadata_bytes(filename: str, data: bytes) -> None: 21 | save_metadata_string(filename, data.decode()) 22 | 23 | 24 | def save_metadata_string(filename: str, data: str) -> None: 25 | # create directory 26 | create_dirs(filename) 27 | 28 | # save metadata 29 | with open(filename, "w", encoding="utf-8") as data_file: 30 | data_file.write(data) 31 | 32 | 33 | def read_metadata_string(filename: str) -> str: 34 | with open(filename, "r", encoding="utf-8") as data_file: 35 | return data_file.read() 36 | 37 | 38 | def read_metadata_bytes(filename: str) -> bytes: 39 | with open(filename, "rb") as data_file: 40 | return data_file.read() 41 | 42 | 43 | def string_match_failure(expected: str, actual: str) -> None: 44 | if len(expected) != len(actual): 45 | raise ValueError("string lengths don't match") 46 | 47 | found = -1 48 | for i in range(len(expected)): 49 | if expected[i] != actual[i]: 50 | found = i 51 | break 52 | 53 | # expected 54 | for i in range(len(expected)): 55 | if i == found: 56 | print(f"\033[0;31m {expected[i]}", end="") 57 | else: 58 | print(f"\033[0m {expected[i]}", end="") 59 | print() 60 | 61 | # actual 62 | for i in range(len(expected)): 63 | if i == found: 64 | print(f"\033[0;31m {actual[i]}", end="") 65 | else: 66 | print(f"\033[0m {actual[i]}", end="") 67 | print() 68 | 69 | if found != -1: 70 | raise ValueError(f"string mismatch at position {found}") 71 | --------------------------------------------------------------------------------