Views
No views yet
1import requests, base64, json
2
3ENDPOINT_URL = "endpoints.huggingface.cloud" # 🌐 replace with your URL endpoint
4HF_TOKEN = "hf_token" # 🔑 replace with your HF token
5AUDIO_FILE = "audio.mp3" # 🔊 path to your local audio file
6
7vad_params = {
8 "min_silence_duration_ms": 100,
9 "speech_pad_ms": 30,
10 "min_speech_duration_ms": 40,
11 "neg_threshold": 0.2,
12 }
13
14headers = {"Authorization": f"Bearer {HF_TOKEN}"}
15
16def trans_fast(audiofile, params):
17 """
18 audiofile: path to audio file
19 params: dict containing
20 - 'parameters' dict to pass to transcription model
21 - 'batched' argument (optional), defaults to True to use faster_whisper batched inference
22 """
23 with open(audiofile, "rb") as f:
24 data = f.read() # read the file
25 encoded_audio = base64.b64encode(data).decode('utf-8') # encode in b64 to send for transcription
26 # Send audio bytes and params
27 payload = {
28 "inputs": encoded_audio,
29 **params
30 }
31 response = requests.post(ENDPOINT_URL, headers=headers, json=payload)
32 return response.json()
33
34
35params = {
36 # dict of parameters for faster_whisper transcription
37 "parameters": {"language": "en", "vad_parameters": vad_params},
38 # whether or not to use batched mode (defaults to True)
39 # "batched": True,
40 }
41# Example usage
42transcript = trans_fast(AUDIO_FILE, params)
43print(transcript)ct2-transformers-converter --model distil-whisper/distil-large-v3 --output_dir faster-distil-whisper-large-v3 \
--copy_files tokenizer.json preprocessor_config.json --quantization float16compute_type option in CTranslate2.