#twilio/twiML with deepgram

1 messages · Page 1 of 1 (latest)

tardy walrus
#

Hey can anyone help

  • the speech to text, i'm using twiML <record> method to get the audio file url
  • when generation speech for text, the code provide me with a audio file but when then twiML <play> method requires a audio url, which make the latency greater as not i have to upload the file to a storage and then provide the url

this is the code

const incoming = async (req, res) => {
    try {
        const voiceResponse = new twiml.VoiceResponse();
        voiceResponse.say({ language: "hi-IN" }, INITIAL_MESSAGE);
        voiceResponse.record({
            timeout: 3,
            playBeep: false,
            action: "/api/v1/respond",
        });
        
        res.set("Content-Type", "application/xml").send(
            voiceResponse.toString()
        );
    } catch (error) {
        console.error(error);
        res.status(500).json({ error: error.message });
    }
};

const response = async (req, res) => {
    try {
        const { RecordingUrl: recordingUrl } = req.body;

        console.log(recordingUrl);
        const transcript = await transcribeUrl(recordingUrl);
        console.log(transcript);

then this is my transcriber code

const transcribeUrl = async (url) => {
    const deepgram = createClient(apiKey);
    const { result, error } = await deepgram.listen.prerecorded.transcribeUrl(
        {
            url: `${url}.mp3`,
        },
        {
            model: "nova-2",
            smart_format: true,
        }
    );

    if (error) throw error;
    if (!error) {
        return result;
    }
};

the issue that i'm getting is that when i set the URL from twiML, it says in the documentation that it to get .mp3 just add .mp3 in it, but when i try to use the url it gives 401.. i tried opening the url in my browser, it gives a proup and ask for credentails, how do i tackle this, there is no way given in the documentation to provide credentails to the recordingURL

cinder flumeBOT
#

Thanks for asking your question. Please be sure to reply with as much detail as possible so we can assist you efficiently. Such as:

  • Provide the request_id if you've a question about a transcription response.
  • The options you used or the api.deepgram.com URL you sent your request to, including parameters.
  • Any code snippets you can include.
  • Any audio you can include, or if you can't share it here please email it to us at [email protected] and provide a link to this thread.
feral thorn
#

Could you try doing it as a .wav file instead?

tardy walrus
#

same issue with .wav also

feral thorn
#

Is the URL a twilio URL? And is the popup asking for credentials coming from twilio?

tardy walrus
feral thorn
#

That's great. Can you tell me what about this code answered your question? I'm going to work on improving our Twilio content next week so based on this problem you ran into (and the solution you found), I would like to create some supporting content so that other people don't get stuck like you did

tardy walrus
#

from deepgram documentation i was not able to understand the flow of the websocket connected with twilio stream, this code explains the flow very well. also i got this repo from your answers on a different post

feral thorn
#

Ok thanks for sharing this. I'm starting on improving Twilio docs today so this is helpful

cinder flumeBOT
#

Hey there @tardy walrus~! Did you forget about this thread? Let us know if you still need help!