Package: deepgram-unstable-sdk
Deepgram Python SDKOfficial Python SDK forDeepgram. Power your apps with world-class speech and Language AI models.Deepgram Python SDKDocumentationGetting an API KeyRequirementsInstallationQuickstartsPreRecorded Audio Transcription QuickstartLive Audio Transcription QuickstartExamplesDevelopment and ContributingGetting HelpDocumentationYou can learn more about the Deepgram API atdevelopers.deepgram.com.Getting an API Key🔑 To access the Deepgram API you will need afree Deepgram API Key.RequirementsPython(version ^3.10)InstallationTo install the latest version available (which will guarantee change over time):pipinstalldeepgram-sdkIf you are going to write an application to consume this SDK, it'shighly recommendedand aprogramming stapleto pin to atleasta major version of an SDK (ie==2.*) orwith due diligence, to a minor and/or specific version (ie==2.1.*or==2.12.0, respectively). If you are unfamiliar withsemantic versioning or semver, it's a must-read.In arequirements.txtfile, pinning to a major (or minor) version, like if you want to stick to using the SDKv2.12.0release, that can be done like this:deepgram-sdk==2.*Or using pip:pipinstalldeepgram-sdk==2.*Pinning to a specific version can be done like this in arequirements.txtfile:deepgram-sdk==2.12.0Or using pip:pipinstalldeepgram-sdk==2.12.0We guarantee that major interfaces will not break in a given major semver (ie2.*release). However, all bets are off moving from a2.*to3.*major release. This follows standard semver best-practices.QuickstartsThis 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 QuickstartYou can find awalkthroughon 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 variablesdeepgram=DeepgramClient()# STEP 2 Call the transcribe_url method on the prerecorded classoptions=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 QuickstartYou can find awalkthroughon our documentation site. Transcribing Live Audio can be done using the following sample code:deepgram=DeepgramClient()# Create a websocket connection to Deepgramoptions=LiveOptions(punctuate=True,language="en-US",encoding="linear16",channels=1,sample_rate=16000,)defon_message(result=None):ifresultisNone:returnsentence=result.channel.alternatives[0].transcriptiflen(sentence)==0:returnprint(f"speaker:{sentence}")defon_metadata(metadata=None):ifmetadataisNone:returnprint(f"\n{metadata}\n")defon_error(error=None):iferrorisNone:returnprint(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 microphonemicrophone=Microphone(dg_connection.send)# start microphonemicrophone.start()# wait until finishedinput("Press Enter to stop recording...\n\n")# Wait for the microphone to closemicrophone.finish()# Indicate that we've finisheddg_connection.finish()print("Finished")ExamplesThere are examples foreveryAPI call in this SDK. You can find all of these examples in theexamples folderat the root of this repo.These examples provide:PreRecorded Audio Transcription:From an Audio File -examples/prerecorded/fileFrom an URL -examples/prerecorded/urlLive Audio Transcription:From a Microphone -examples/streaming/microphoneFrom an HTTP Endpoint -examples/streaming/httpManagement API exercise the fullCRUDoperations for:Balances -examples/manage/balancesInvitations -examples/manage/invitationsKeys -examples/manage/keysMembers -examples/manage/membersProjects -examples/manage/projectsScopes -examples/manage/scopesUsage -examples/manage/usageTo run each example set theDEEPGRAM_API_KEYas an environment variable, thencdinto each example folder and execute the example:go run main.py.Development and ContributingInterested in contributing? We ❤️ pull requests!To make sure our community is safe for all, be sure to review and agree to ourCode of Conduct. Then see theContributionguidelines for more information.PrerequisitesIn order to develop new features for the SDK itself, you first need to uninstall any previous installation of thedeepgram-sdkand then install/pip the dependencies contained in therequirements.txtthen instruct python (via pip) to use the SDK by installing it locally.From the root of the repo, that would entail:pipuninstalldeepgram-sdk
pipinstall-rrequirements.txt
pipinstall-e.TestingIf you are looking to contribute or modify pytest code, then you need to install the following dependencies:pipinstall-rrequirements-dev.txtGetting HelpWe love to hear from you so if you have questions, comments or find a bug in the
project, let us know! You can either:Open an issue in this repositoryJoin the Deepgram Github Discussions CommunityJoin the Deepgram Discord Community