Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion apps/docs/content/docs/audio.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ title: Audio API
description: Access Quran audio recitations from different reciters.
---

The Audio API provides access to audio recitations including chapter audio and verse-by-verse audio with timing.
The Audio API provides access to recitation audio from the authenticated Content API, including chapter audio and verse-by-verse audio with optional timing data.

## Choose the Right Audio Source

| Use case | Fetch from | Returned shape | Notes |
| --- | --- | --- | --- |
| Single-word pronunciation | `word.audioUrl` from the [Verses API](./verses) | Relative `wbw/...` asset path | Resolve it against `https://audio.qurancdn.com/` before playing it in the browser. |
| Chapter playback | `client.audio.findAllChapterRecitations()` or `client.audio.findChapterRecitationById()` | Full chapter `audioUrl` | Use this for continuous chapter playback. |
| Ayah playback with timing | `client.audio.findVerseRecitationsByChapter()` or `client.audio.findVerseRecitationsByKey()` | Verse recitation `url` plus optional `segments` | Use this for ayah recitations and highlighting. This is distinct from `word.audioUrl`. |

## Chapter Recitations

Expand Down Expand Up @@ -61,6 +69,8 @@ audioFiles.forEach((audio) => {
name="VerseRecitation"
/>

`segments` provide word-level timing inside the recitation for highlighting and seek. They do not change how `word.audioUrl` works.

### By Verse Key

```ts
Expand Down
2 changes: 2 additions & 0 deletions apps/docs/content/docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ bun add @quranjs/api

## Quick Start

> Note: The SDK can run in browser code, but keep `clientSecret` on your server and make authenticated Content API calls from a backend or server-side runtime. Public word-by-word audio playback uses the separate `word.audioUrl` asset path described in the [Verses API](./verses).

```ts
import { Language, QuranClient } from "@quranjs/api";

Expand Down
6 changes: 3 additions & 3 deletions apps/docs/content/docs/resources.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ console.log(styles.mujawwad); // Mujawwad reciters
```ts
const media = await client.resources.findVerseMedia();

console.log(media.unicode); // Font URL
console.log(media.image); // Images base URL
console.log(media.audio); // Audio base URL
console.log(media.name); // Resource name
console.log(media.authorName); // Author or curator
console.log(media.languageName); // Associated language
```

### VerseMediaResource Type
Expand Down
27 changes: 26 additions & 1 deletion apps/docs/content/docs/verses.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,30 @@ const verse = await client.verses.findByKey("1:1", {
});
```

Requesting `words: true` can include `word.audioUrl` for each word. That value is a relative word-by-word asset path such as `wbw/001_001_001.mp3`, not a `/content/api/v4/...` endpoint.

### Word Audio Paths

```ts
const verse = await client.verses.findByKey("1:1", {
words: true,
wordFields: {
audio: true,
location: true,
},
});

const firstWord = verse.words?.[0];
const wordAudioUrl = firstWord
? new URL(
firstWord.audioUrl.replace(/^\/+/, ""),
"https://audio.qurancdn.com/",
).toString()
: null;
```

Use `word.audioUrl` for single-word pronunciation playback. For chapter or ayah recitations, and for timing `segments`, use the [Audio API](./audio) instead.

### With Tafsir

```ts
Expand Down Expand Up @@ -104,10 +128,11 @@ const random = await client.verses.findRandom({
const verse = await client.verses.findByKey("1:1", {
words: true,
wordFields: {
audio: true,
textUthmani: true,
transliteration: true,
translation: true,
audio: true,
location: true,
},
});
```
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/types/api/Word.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export enum CharType {
export interface Word {
id?: number;
position: number;
audioUrl: string;
audioUrl: string; // Relative word-by-word audio path, e.g. wbw/001_001_001.mp3
charTypeName: CharType;
codeV1?: string;
codeV2?: string;
Expand Down