Skip to content

Commit 796a619

Browse files
authored
Fix snippet + generate from @huggingface/inference (#1624)
* Fix snippet + generate from @huggingface/inference * dummy
1 parent 8938953 commit 796a619

21 files changed

+655
-174
lines changed

docs/api-inference/tasks/audio-classification.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ For more details about the `audio-classification` task, check out its [dedicated
2929

3030
### Recommended models
3131

32+
- [speechbrain/google_speech_command_xvector](https://huggingface.co/speechbrain/google_speech_command_xvector): An easy-to-use model for command recognition.
3233
- [ehcalabres/wav2vec2-lg-xlsr-en-speech-emotion-recognition](https://huggingface.co/ehcalabres/wav2vec2-lg-xlsr-en-speech-emotion-recognition): An emotion recognition model.
34+
- [facebook/mms-lid-126](https://huggingface.co/facebook/mms-lid-126): A language identification model.
3335

3436
Explore all available models and find the one that suits you best [here](https://huggingface.co/models?inference=warm&pipeline_tag=audio-classification&sort=trending).
3537

@@ -40,7 +42,7 @@ Explore all available models and find the one that suits you best [here](https:/
4042

4143
<curl>
4244
```bash
43-
curl https://api-inference.huggingface.co/models/ehcalabres/wav2vec2-lg-xlsr-en-speech-emotion-recognition \
45+
curl https://router.huggingface.co/hf-inference/models/speechbrain/google_speech_command_xvector \
4446
-X POST \
4547
--data-binary '@sample1.flac' \
4648
-H 'Authorization: Bearer hf_***'
@@ -51,14 +53,14 @@ curl https://api-inference.huggingface.co/models/ehcalabres/wav2vec2-lg-xlsr-en-
5153
```py
5254
import requests
5355

54-
API_URL = "https://api-inference.huggingface.co/models/ehcalabres/wav2vec2-lg-xlsr-en-speech-emotion-recognition"
56+
API_URL = "https://router.huggingface.co/hf-inference/v1"
5557
headers = {"Authorization": "Bearer hf_***"}
5658

5759
def query(filename):
58-
with open(filename, "rb") as f:
59-
data = f.read()
60-
response = requests.post(API_URL, headers=headers, data=data)
61-
return response.json()
60+
with open(filename, "rb") as f:
61+
data = f.read()
62+
response = requests.post(API_URL, headers=headers, data=data)
63+
return response.json()
6264

6365
output = query("sample1.flac")
6466
```
@@ -71,7 +73,7 @@ To use the Python client, see `huggingface_hub`'s [package reference](https://hu
7173
async function query(filename) {
7274
const data = fs.readFileSync(filename);
7375
const response = await fetch(
74-
"https://api-inference.huggingface.co/models/ehcalabres/wav2vec2-lg-xlsr-en-speech-emotion-recognition",
76+
"https://router.huggingface.co/hf-inference/models/speechbrain/google_speech_command_xvector",
7577
{
7678
headers: {
7779
Authorization: "Bearer hf_***",

docs/api-inference/tasks/automatic-speech-recognition.md

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ For more details about the `automatic-speech-recognition` task, check out its [d
3030
### Recommended models
3131

3232
- [openai/whisper-large-v3](https://huggingface.co/openai/whisper-large-v3): A powerful ASR model by OpenAI.
33-
- [pyannote/speaker-diarization-3.1](https://huggingface.co/pyannote/speaker-diarization-3.1): Powerful speaker diarization model.
33+
- [facebook/seamless-m4t-v2-large](https://huggingface.co/facebook/seamless-m4t-v2-large): An end-to-end model that performs ASR and Speech Translation by MetaAI.
3434

3535
Explore all available models and find the one that suits you best [here](https://huggingface.co/models?inference=warm&pipeline_tag=automatic-speech-recognition&sort=trending).
3636

@@ -41,7 +41,7 @@ Explore all available models and find the one that suits you best [here](https:/
4141

4242
<curl>
4343
```bash
44-
curl https://api-inference.huggingface.co/models/openai/whisper-large-v3 \
44+
curl https://router.huggingface.co/hf-inference/models/openai/whisper-large-v3 \
4545
-X POST \
4646
--data-binary '@sample1.flac' \
4747
-H 'Authorization: Bearer hf_***'
@@ -52,14 +52,14 @@ curl https://api-inference.huggingface.co/models/openai/whisper-large-v3 \
5252
```py
5353
import requests
5454

55-
API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v3"
55+
API_URL = "https://router.huggingface.co/hf-inference/v1"
5656
headers = {"Authorization": "Bearer hf_***"}
5757

5858
def query(filename):
59-
with open(filename, "rb") as f:
60-
data = f.read()
61-
response = requests.post(API_URL, headers=headers, data=data)
62-
return response.json()
59+
with open(filename, "rb") as f:
60+
data = f.read()
61+
response = requests.post(API_URL, headers=headers, data=data)
62+
return response.json()
6363

6464
output = query("sample1.flac")
6565
```
@@ -68,11 +68,30 @@ To use the Python client, see `huggingface_hub`'s [package reference](https://hu
6868
</python>
6969

7070
<js>
71+
Using `huggingface.js`:
72+
```js
73+
import { HfInference } from "@huggingface/inference";
74+
75+
const client = new HfInference("hf_***");
76+
77+
const data = fs.readFileSync("sample1.flac");
78+
79+
const output = await client.automaticSpeechRecognition({
80+
data,
81+
model: "openai/whisper-large-v3",
82+
provider: "hf-inference",
83+
});
84+
85+
console.log(output);
86+
87+
```
88+
89+
Using `fetch`:
7190
```js
7291
async function query(filename) {
7392
const data = fs.readFileSync(filename);
7493
const response = await fetch(
75-
"https://api-inference.huggingface.co/models/openai/whisper-large-v3",
94+
"https://router.huggingface.co/hf-inference/models/openai/whisper-large-v3",
7695
{
7796
headers: {
7897
Authorization: "Bearer hf_***",
@@ -143,5 +162,5 @@ For more information about Inference API headers, check out the parameters [guid
143162
| **text** | _string_ | The recognized text. |
144163
| **chunks** | _object[]_ | When returnTimestamps is enabled, chunks contains a list of audio chunks identified by the model. |
145164
| **&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text** | _string_ | A chunk of text identified by the model |
146-
| **&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;timestamps** | _number[]_ | The start and end timestamps corresponding with the text |
165+
| **&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;timestamp** | _number[]_ | The start and end timestamps corresponding with the text |
147166

0 commit comments

Comments
 (0)