https://github.com/dbushell/audio-duration
🔊 Deno native audio duration for MP3 / M4A / M4B (no dependencies)
https://github.com/dbushell/audio-duration
deno javascript typescript
Last synced: 24 days ago
JSON representation
🔊 Deno native audio duration for MP3 / M4A / M4B (no dependencies)
- Host: GitHub
- URL: https://github.com/dbushell/audio-duration
- Owner: dbushell
- License: mit
- Created: 2023-03-11T13:33:16.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-26T06:22:56.000Z (10 months ago)
- Last Synced: 2024-07-26T07:42:09.666Z (10 months ago)
- Topics: deno, javascript, typescript
- Language: TypeScript
- Homepage: https://jsr.io/@dbushell/audio-duration
- Size: 18.6 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🔊 Deno Audio Duration
Get the **millisecond** duration of audio files in pure **Deno** flavoured JavaScript. Currently MP3 / M4A / M4B formats are supported.
[](https://jsr.io/@dbushell/audio-duration) [](https://jsr.io/@dbushell/audio-duration) [](https://jsr.io/@dbushell)
## Usage
```javascript
import {duration} from 'jsr:@dbushell/audio-duration';const ms = await duration('/path/to/audio.mp3');
```The `duration` function will detect audio formats based on the file extension. Import and use `mp3Duration` and `m4aDuration` to bypass this detection.
## Other Solutions
If this module is insufficient use another tool with `Deno.Command`:
With [ffprobe](https://ffmpeg.org/ffprobe.html):
```sh
ffprobe -loglevel quiet -show_format -print_format json audio.mp3
```With [exiftool](https://exiftool.org/):
```sh
exiftool -j -Duration audio.mp3
```For example:
```typescript
const stat = await Deno.stat(entry.path);
const command = new Deno.Command('exiftool', {
args: ['-j', '-Duration', `${entry.path}`]
});
const {stdout} = await command.output();
const json = JSON.parse(
new TextDecoder().decode(stdout)
);
```You'll need to parse the output.
* * *
[MIT License](/LICENSE) | Copyright © 2024 [David Bushell](https://dbushell.com)