Skip to main content

The official Python SDK for the Deepgram automated speech recognition platform.

Project description

Deepgram Python SDK

Discord GitHub Workflow Status PyPI Contributor Covenant

Official Python SDK for Deepgram. Power your apps with world-class speech and Language AI models.

This SDK only supports hosted usage of api.deepgram.com.

Documentation

You can learn more about the Deepgram API at developers.deepgram.com.

Getting an API Key

🔑 To access the Deepgram API you will need a free Deepgram API Key.

Requirements

Python (version ^3.10)

NOTE: Althought many older versions should work.

Installation

pip install deepgram-sdk

Quickstarts

This SDK aims to reduce complexity and abtract/hide some internal Deepgram details that clients shouldn't need to know about. However you can still tweak options and settings if you need.

PreRecorded Audio Transcription Quickstart

You can find a walkthrough on our documentation site. Transcribing Pre-Recorded Audio can be done using the following sample code:

AUDIO_URL = {
    "url": "https://static.deepgram.com/examples/Bueller-Life-moves-pretty-fast.wav"
}

# STEP 1 Create a Deepgram client using the API key from environment variables
deepgram = DeepgramClient()

# STEP 2 Call the transcribe_url method on the prerecorded class
options = PrerecordedOptions(
    model="nova",
    smart_format=True,
    summarize="v2",
)
url_response = deepgram.listen.prerecorded.v("1").transcribe_url(AUDIO_URL, options)
print(url_response)

Live Audio Transcription Quickstart

You can find a walkthrough on our documentation site. Transcribing Live Audio can be done using the following sample code:

deepgram = DeepgramClient()

# Create a websocket connection to Deepgram
options = LiveOptions(
    punctuate=True,
    language="en-US",
    encoding="linear16",
    channels=1,
    sample_rate=16000,
)

def on_message(result=None):
    if result is None:
        return
    sentence = result.channel.alternatives[0].transcript
    if len(sentence) == 0:
        return
    print(f"speaker: {sentence}")

def on_metadata(metadata=None):
    if metadata is None:
        return
    print(f"\n{metadata}\n")


def on_error(error=None):
    if error is None:
        return
    print(f"\n{error}\n")

dg_connection = deepgram.listen.live.v("1")
dg_connection.start(options)

dg_connection.on(LiveTranscriptionEvents.Transcript, on_message)
dg_connection.on(LiveTranscriptionEvents.Metadata, on_metadata)
dg_connection.on(LiveTranscriptionEvents.Error, on_error)

# create microphone
microphone = Microphone(dg_connection.send)

# start microphone
microphone.start()

# wait until finished
input("Press Enter to stop recording...\n\n")

# Wait for the microphone to close
microphone.finish()

# Indicate that we've finished
dg_connection.finish()

print("Finished")

Examples

There are examples for every API call in this SDK. You can find all of these examples in the examples folder at the root of this repo.

These examples provide:

To run each example set the DEEPGRAM_API_KEY as an environment variable, then cd into each example folder and execute the example: go run main.py.

Development and Contributing

Interested in contributing? We ❤️ pull requests!

To make sure our community is safe for all, be sure to review and agree to our Code of Conduct. Then see the Contribution guidelines for more information.

Getting Help

We love to hear from you so if you have questions, comments or find a bug in the project, let us know! You can either:

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

deepgram-sdk-3.0.0rc2.tar.gz (27.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

deepgram_sdk-3.0.0rc2-py3-none-any.whl (48.8 kB view details)

Uploaded Python 3

File details

Details for the file deepgram-sdk-3.0.0rc2.tar.gz.

File metadata

  • Download URL: deepgram-sdk-3.0.0rc2.tar.gz
  • Upload date:
  • Size: 27.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for deepgram-sdk-3.0.0rc2.tar.gz
Algorithm Hash digest
SHA256 b4a89dc38235eb66b38ee1f4638933908f1855fc7576e62aad2f89ec566302fd
MD5 ba537816ae78be702d9f98629b5844b5
BLAKE2b-256 936c105befbe46e3a1b9906327312d0f247297a1d7572e18670a735a74e7692f

See more details on using hashes here.

File details

Details for the file deepgram_sdk-3.0.0rc2-py3-none-any.whl.

File metadata

File hashes

Hashes for deepgram_sdk-3.0.0rc2-py3-none-any.whl
Algorithm Hash digest
SHA256 d9f9bb66b597591d474c2c3faa18513f31485a6d7760c04b089b5f2c83dbee86
MD5 e2143c2e022dcc021aa16c8a241e6336
BLAKE2b-256 af5fa60422ed116a67add3de7441d2708801d63c593cd7bb31c6084b82baa824

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page