daily-co / daily-python

Daily Client SDK for Python
BSD 2-Clause "Simplified" License
35 stars 7 forks source link

Unable to start transcription #2

Closed kylemcdonald closed 9 months ago

kylemcdonald commented 9 months ago

I would like to use the Deepgram-powered transcription service for my voice call app.

I tried building a simple app that only starts and stops transcription:

import argparse
from daily import Daily, CallClient, EventHandler
from time import sleep

class MyEventHandler(EventHandler):
    def on_transcription_message(self, message):
        print("Transcription message:", message)

class DailyApp:
    def __init__(self):
        self.client = CallClient(event_handler=MyEventHandler())

    def join(self, meeting_url):
        self.client.join(meeting_url)
        sleep(2)
        self.client.start_transcription()

    def leave(self):
        self.client.stop_transcription()
        self.client.leave()

def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("-m", "--meeting", required=True, help="Meeting URL")
    args = parser.parse_args()

    Daily.init()

    app = DailyApp()
    app.join(args.meeting)

    try:
        while True:
            sleep(0.1)
    except KeyboardInterrupt:
        pass
    finally:
        app.leave()
        sleep(2)

if __name__ == "__main__":
    main()

I call the app like this:

python transcribe.py  -m https://kcimc.daily.co/[my channel name]

But when I start the app I get this error:

{
    "timestamp": "2023-10-06T06:38:23.522257Z",
    "level": "ERROR",
    "fields": {
        "message": "startTranscription (request 1) encountered an error: Transcription(SfuClient(InvalidTranscriptionProperties(UnknownCallClientError)))"
    },
    "target": "daily_core::native::ffi::call_client",
}

How can I fix this?

I thought maybe I need to enable transcription:

curl -H "Content-Type: application/json" \
    -H "Authorization: Bearer <daily.co key>" \
    -XPOST -d '{"properties":{"enable_transcription": "deepgram:<deepgram key>"}}' \
    https://api.daily.co/v1/

But I got the same error.

Or maybe it is permissions:

curl -H "Content-Type: application/json" \
    -H "Authorization: Bearer <daily.co key>" \
    -XPOST -d '{"properties":{"permissions": {"canSend": true, "hasPresence": true, "canAdmin": true}}}' \
    https://api.daily.co/v1/

But I got the same error.

Please help 🙏

aconchillo commented 9 months ago

Hi @kylemcdonald . Thank you for trying out daily-python. I believe the issue might be that you need to join the meeting with a meeting token. You can easily generate one with our REST API:

https://docs.daily.co/reference/rest-api/meeting-tokens/create-meeting-token

Once you have the token you can just pass it to the join() function:

client.join(meeting_url, meeting_token = TOKEN);

Let us know if this solves the issue.

aconchillo commented 9 months ago

Just to clarify:

  1. Add your Deepgram key to the enable_transcription domain property as you already mentioned in your message (using your Daily domain API key to make the request):
curl -H "Content-Type: application/json" \
    -H "Authorization: Bearer <daily.co key>" \
    -XPOST -d '{"properties":{"enable_transcription": "deepgram:<deepgram key>"}}' \
    https://api.daily.co/v1/
  1. Get a meeting token for an owner or an admin with transcription permissions, for example:
curl -H "Content-Type: application/json" \
     -H "Authorization: Bearer <daily.co key>" \
     -XPOST -d \
     '{"properties":{"is_owner":true}}' \
     https://api.daily.co/v1/meeting-tokens
  1. Use the returned token in client.join(URL, meeting_token = TOKEN).
kylemcdonald commented 9 months ago

I can confirm that I needed to join with a token, and now it works. Thank you for your help.

For anyone else who may read this in the future, I did not test whether I can transcribe with "is_owner":false.