Views
No views yet
Whisper is a general-purpose speech recognition model. It is trained on a large dataset of diverse audio and is also a multi-task model that can perform multilingual speech recognition as well as speech translation and language identification.
handler task for automatic-speech-recognition for 🤗 Inference Endpoints using OpenAIs new Whisper model. The code for the customized pipeline is in the pipeline.py.handler.pyrequests library.1# load audio file
2wget https://cdn-media.huggingface.co/speech_samples/sample1.flac
3
4# run request
5curl --request POST \
6 --url https://{ENDPOINT}/ \
7 --header 'Content-Type: audio/x-flac' \
8 --header 'Authorization: Bearer {HF_TOKEN}' \
9 --data-binary '@sample1.flac'1import json
2from typing import List
3import requests as r
4import base64
5import mimetypes
6
7ENDPOINT_URL=""
8HF_TOKEN=""
9
10def predict(path_to_audio:str=None):
11 # read audio file
12 with open(path_to_audio, "rb") as i:
13 b = i.read()
14 # get mimetype
15 content_type= mimetypes.guess_type(path_to_audio)[0]
16
17 headers= {
18 "Authorization": f"Bearer {HF_TOKEN}",
19 "Content-Type": content_type
20 }
21 response = r.post(ENDPOINT_URL, headers=headers, data=b)
22 return response.json()
23
24prediction = predict(path_to_audio="sample1.flac")
25
26prediction
27{"text": " going along slushy country roads and speaking to damp audiences in draughty school rooms day after day for a fortnight. He'll have to put in an appearance at some place of worship on Sunday morning, and he can come to us immediately afterwards."}