visit
In this digital age where virtual conferences are a dime a dozen, we see a large number of them recorded for future records. There are many uses for these records, including sharing with people who were unable to attend live, distributing for use as training, and keeping backups for future reference. One aspect of these recordings that is taken for granted, however, is accessibility. In this blog, we will demonstrate how to take recordings from your Dolby.io Communications conferences, and use to transcribe them to text.
pip3 install asyncio deepgram-sdk dolbyio-rest-apis
In this case, we want to fill in the consumer key and secret with our from our Communications APIs (not Media). We then call the get_api_access_token
endpoint within a function so we can generate a fresh token every time we make another call. This is not the most secure way to handle this, but will ensure we don’t run into any expired credentials down the road. To learn more, see .
from dolbyio_rest_apis.communications import authentication
import asyncio
# Input your Dolby.io Communications Credentials here
CONSUMER_KEY = "<DOLBYIO_CONSUMER_KEY>"
CONSUMER_SECRET = "<DOLBYIO_CONSUMER_SECRET>"
# Create a function that will generate a new api access token when needed
async def gen_token():
response = await authentication.get_api_access_token(CONSUMER_KEY, CONSUMER_SECRET)
return response['access_token']
print(f"Access Token: {await gen_token()}")
Now that we can call the APIs, we first want to get the internal conference ID of the recording we want to transcribe. We can do this by simply calling the get_conferences
endpoint with our token.
from dolbyio_rest_apis.communications.monitor import conferences
response = await conferences.get_conferences(await gen_token())
# Save the most recent conference. Change '-1' to whichever conference you want.
confId = response['conferences'][-1]['confId']
print(confId)
Note that in this code sample, we are using the parameter: ['conferences'][-1]['confId']
. This will pull only the most recent conference in the list as noted by the "-1" array value. If you are automating this to work with every newly generated conference, this likely will not be an issue. However if you are looking to do this with a specific conference, we suggest using to obtain the desired conference ID.
from dolbyio_rest_apis.communications.monitor import recordings
# Save only the mp3 file and return as a URL.
# If your conference does not use Dolby Voice, use 'download_mp3_recording' instead.
# //github.com/dolbyio-samples/dolbyio-rest-apis-client-python/blob/main/client/src/dolbyio_rest_apis/communications/monitor/recordings.py
response = await recordings.get_dolby_voice_recordings(await gen_token(), confId)
recording_url = response['url']
print(recording_url)
from deepgram import Deepgram
# Your Deepgram API Key
DEEPGRAM_API_KEY = '<DEEPGRAM_API_KEY>'
# Location of the file you want to transcribe. Should include filename and extension.
FILE = recording_url
async def main():
# Initialize the Deepgram SDK
deepgram = Deepgram(DEEPGRAM_API_KEY)
# file is remote
# Set the source
source = {
'url': FILE
}
# Send the audio to Deepgram and get the response
response = await asyncio.create_task(
deepgram.transcription.prerecorded(
source,
{
'punctuate': True
}
)
)
# Write only the transcript to the console
print(response['results']['channels'][0]['alternatives'][0]['transcript'])
try:
await main()
# If not running in a Jupyter notebook, run main with this line instead:
# asyncio.run(main())
except Exception as e:
exception_type, exception_object, exception_traceback = sys.exc_info()
line_number = exception_traceback.tb_lineno
print(f'line {line_number}: {exception_type} - {e}')
The Deepgram response provides many datapoints related to our speech, but to pull only the transcription of the file, we are calling ['results']['channels'][0]['alternatives'][0]['transcript']
. Feel free to modify the response to generate whatever is most relevant to your needs. For the above sample provided, the result of the transcription is as follows:
Following text is a transcription of the s en of the parchment declaration of independence. The document on display in the rot the national archives Museum. The spelling and punctuation reflects the originals.
Also published .