Next.js Discord

Discord Forum

Very weird issue. Works with Pages Directory but not with App router

Unanswered
Great Spotted Woodpecker posted this in #help-forum
Open in Discord
Great Spotted WoodpeckerOP
Below code works with Pages directory but not with app routers


//route.js
const { Speechmatics } = require('speechmatics');


const sm = new Speechmatics(API_KEY); //give your api key
const fileUrl = 'AWS file url or any audio url';

async function transcribeFile() {
try {
const transcriptText = await sm.batch.transcribe({
input: { fetch: { url: fileUrl } },
transcription_config: { language: 'en' },
format: 'json-v2'
});
console.log(transcriptText);
return transcriptText;
} catch (error) {
console.log(error);
return error;
}
}

export async function GET() {
console.log("I am here");

const transcriptJson = await transcribeFile();
return Response.json(transcriptJson, { status: 200 })
}

I am not getting data from the API. basically return Response.json(transcriptJson, { status: 200 }) never gets called.

The request just time out. It works with the Pages directory.

2 Replies

Great Spotted WoodpeckerOP
I gave the complete code for route.js whic does not work with route handlers with app routers
const { Speechmatics } = require('speechmatics');


const sm = new Speechmatics(API_KEY);
const fileUrl = 'AWS file url or any audio url';

async function transcribeFile() {
try {
const transcriptText = await sm.batch.transcribe({
input: { fetch: { url: fileUrl } },
transcription_config: { language: 'en' },
format: 'json-v2'
});
console.log(transcriptText);
return transcriptText;
} catch (error) {
console.log(error);
return error;
}
}

export async function GET() {
console.log("I am here");

const transcriptJson = await transcribeFile();
return Response.json(transcriptJson, { status: 200 })
}

I am not getting data from the API. basically return Response.json(transcriptJson, { status: 200 }) never gets called.

The request just time out. It works with the Pages directory.