feat(docs): Add documentation for the new audio pipelines · roygitonga/transformers-php@144d508 · GitHub
Skip to content

Commit 144d508

Browse files
feat(docs): Add documentation for the new audio pipelines
1 parent 27aab75 commit 144d508

34 files changed

Lines changed: 1013 additions & 964 deletions

‎.github/workflows/release.yml‎

Lines changed: 19 additions & 27 deletions

‎composer.json‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@
1818
"codewithkyrian/jinja-php": "^1.0",
1919
"codewithkyrian/transformers-libsloader": "^2.0",
2020
"imagine/imagine": "^1.3",
21-
"rokka/imagine-vips": "^0.31.0",
2221
"rindow/rindow-math-matrix": "^2.0",
2322
"rindow/rindow-matlib-ffi": "^1.0",
2423
"rindow/rindow-openblas-ffi": "^1.0",
25-
"symfony/console": "^6.4|^7.0",
26-
"ffi/location": "^1.0"
24+
"symfony/console": "^6.4|^7.0"
2725
},
2826
"require-dev": {
2927
"pestphp/pest": "^2.31",
30-
"symfony/var-dumper": "^7.0"
28+
"symfony/var-dumper": "^7.0",
29+
"rokka/imagine-vips": "^0.31.0"
3130
},
3231
"suggest": {
33-
"ext-imagick": "Needed if you want to use the Imagick Driver for image processing",
34-
"ext-gd": "Needed if you want to use the GD Driver for image processing"
32+
"ext-imagick": "Required to use the Imagick Driver for image processing",
33+
"ext-gd": "Required to use the GD Driver for image processing",
34+
"rokka/imagine-vips": "Required to use the VIPS Driver for image processing"
3535
},
3636
"license": "Apache-2.0",
3737
"autoload": {

‎docs/.vitepress/config.mts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ export default defineConfig({
6969
{text: 'Image To Text', link: '/image-to-text'},
7070
{text: 'Image To Image', link: '/image-to-image'},
7171
]
72+
},
73+
{
74+
text: 'Audio Tasks',
75+
collapsed: true,
76+
items: [
77+
{text: 'Audio Classification', link: '/audio-classification'},
78+
{text: 'Automatic Speech Recognition', link: '/automatic-speech-recognition'},
79+
]
7280
}
7381
]
7482
},

‎docs/audio-classification.md‎

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
---
2+
outline: deep
3+
---
4+
5+
# Audio Classification <Badge type="tip" text="^0.5.0" />
6+
7+
Audio classification involves assigning a label or class to an audio input. It can be used to recognize commands,
8+
identify speakers, or detect emotions in speech. The model processes the audio and returns a classification label with a
9+
corresponding confidence score.
10+
11+
## Task ID
12+
13+
- `audio-classification`
14+
15+
## Default Model
16+
17+
- `Xenova/wav2vec2-base-superb-ks`
18+
19+
## Use Cases
20+
21+
Audio classification models have a wide range of applications, including:
22+
23+
- **Command Recognition:** Classifying utterances into a predefined set of commands, often done on-device for fast
24+
response times.
25+
- **Language Identification:** Detecting the language spoken in the audio.
26+
- **Emotion Recognition:** Analyzing speech to identify the emotion expressed by the speaker.
27+
- **Speaker Identification:** Determining the identity of the speaker from a set of known voices.
28+
29+
## Running an Inference Session
30+
31+
Here's how to perform audio classification using the pipeline:
32+
33+
```php
34+
use function Codewithkyrian\Transformers\Pipelines\pipeline;
35+
36+
$classifier = pipeline('audio-classification', 'Xenova/ast-finetuned-audioset-10-10-0.4593');
37+
38+
$audioUrl = __DIR__ . '/../sounds/cat_meow.wav';
39+
40+
$output = $classifier($audioUrl, topK: 4);
41+
```
42+
43+
::: details Click to view output
44+
45+
```php
46+
[
47+
['label' => 'Cat Meow', 'score' => 0.8456],
48+
['label' => 'Domestic Animal', 'score' => 0.1234],
49+
['label' => 'Pet', 'score' => 0.0987],
50+
['label' => 'Mammal', 'score' => 0.0567]
51+
]
52+
```
53+
54+
:::
55+
56+
## Pipeline Input Options
57+
58+
When running the `audio-classification` pipeline, you can use the following options:
59+
60+
- ### `inputs` *(string)*
61+
The audio file(s) to classify. It can be a local file path, a file resource, a URL to an audio file (local or remote),
62+
or an array of these inputs. It's the first argument, so there's no need to pass it as a named argument.
63+
64+
```php
65+
$output = $classifier('https://example.com/audio.wav');
66+
```
67+
68+
- ### `topK` *(int)*
69+
The number of top labels to return. The default is `1`.
70+
71+
```php
72+
$output = $classifier('https://example.com/audio.wav', topK: 4);
73+
```
74+
75+
::: details Click to view output
76+
77+
```php
78+
[
79+
['label' => 'Cat Meow', 'score' => 0.8456],
80+
['label' => 'Domestic Animal', 'score' => 0.1234],
81+
['label' => 'Pet', 'score' => 0.0987],
82+
['label' => 'Mammal', 'score' => 0.0567]
83+
]
84+
```
85+
86+
:::
87+
88+
## Pipeline Outputs
89+
90+
The output of the pipeline is an array containing the classification label and the confidence score. The confidence
91+
score is a value between 0 and 1, with 1 being the highest confidence.
92+
93+
Since the actual labels depend on the model, it's crucial to consult the model's documentation for the specific labels
94+
it uses. Here are examples demonstrating how outputs might differ:
95+
96+
For a single audio file:
97+
98+
```php
99+
['label' => 'Dog Barking', 'score' => 0.9321]
100+
```
101+
102+
For multiple audio files:
103+
104+
```php
105+
[
106+
['label' => 'Dog Barking', 'score' => 0.9321],
107+
['label' => 'Car Horn', 'score' => 0.8234],
108+
['label' => 'Siren', 'score' => 0.7123]
109+
]
110+
```
Lines changed: 146 additions & 0 deletions

0 commit comments

Comments
 (0)