Views
No views yet
.wav).mp3).flac).m4a).ogg)1import requests
2import base64
3
4# Read your audio file
5with open("audio.wav", "rb") as f:
6 audio_bytes = f.read()
7
8# Encode to base64
9audio_base64 = base64.b64encode(audio_bytes).decode("utf-8")
10
11# API endpoint (replace with your endpoint URL after deployment)
12API_URL = "https://api-inference.huggingface.co/models/adithyafp/onnx-whisper-jv"
13
14# Your HuggingFace API token
15headers = {
16 "Authorization": "Bearer YOUR_HF_TOKEN"
17}
18
19# Make request
20response = requests.post(
21 API_URL,
22 headers=headers,
23 json={
24 "inputs": audio_base64,
25 "parameters": {
26 "max_length": 448,
27 "return_timestamps": False
28 }
29 }
30)
31
32# Get result
33result = response.json()
34print(f"Transcription: {result['transcription']}")
35print(f"Duration: {result['metadata']['audio_duration_seconds']:.2f}s")1# Encode audio file to base64
2AUDIO_BASE64=$(base64 -i audio.wav)
3
4# Make API request
5curl -X POST \
6 https://api-inference.huggingface.co/models/adithyafp/onnx-whisper-jv \
7 -H "Authorization: Bearer YOUR_HF_TOKEN" \
8 -H "Content-Type: application/json" \
9 -d "{\"inputs\": \"$AUDIO_BASE64\"}"1from huggingface_hub import InferenceClient
2import base64
3
4client = InferenceClient(token="YOUR_HF_TOKEN")
5
6# Read and encode audio
7with open("audio.wav", "rb") as f:
8 audio_bytes = f.read()
9
10audio_base64 = base64.b64encode(audio_bytes).decode("utf-8")
11
12# Transcribe
13result = client.post(
14 json={"inputs": audio_base64},
15 model="adithyafp/onnx-whisper-jv"
16)
17
18print(result)1async function transcribeAudio(audioFile) {
2 // Read audio file
3 const audioBuffer = await audioFile.arrayBuffer();
4 const audioBase64 = btoa(
5 String.fromCharCode(...new Uint8Array(audioBuffer))
6 );
7
8 // API request
9 const response = await fetch(
10 "https://api-inference.huggingface.co/models/adithyafp/onnx-whisper-jv",
11 {
12 method: "POST",
13 headers: {
14 "Authorization": "Bearer YOUR_HF_TOKEN",
15 "Content-Type": "application/json"
16 },
17 body: JSON.stringify({
18 inputs: audioBase64,
19 parameters: {
20 max_length: 448
21 }
22 })
23 }
24 );
25
26 const result = await response.json();
27 console.log("Transcription:", result.transcription);
28 return result;
29}
30
31// Usage
32const audioFile = document.getElementById('audioInput').files[0];
33transcribeAudio(audioFile);1{
2 "transcription": "Sugeng enjing, kepiye kabare?",
3 "language": "javanese",
4 "status": "success",
5 "metadata": {
6 "audio_duration_seconds": 3.52,
7 "num_tokens": 12,
8 "model": "whisper-large-v2-jv-onnx"
9 }
10}transcription (string): The transcribed text in Javaneselanguage (string): Source language ("javanese")status (string): Request status ("success" or "error")metadata (object):
audio_duration_seconds (float): Duration of input audionum_tokens (int): Number of tokens generatedmodel (string): Model identifier| Parameter | Type | Default | Description |
|---|---|---|---|
max_length | int | 448 | Maximum length of generated tokens |
return_timestamps | bool | false | Return word-level timestamps (future) |
return_token_ids | bool | false | Include raw token IDs in response |
1response = requests.post(
2 API_URL,
3 headers=headers,
4 json={
5 "inputs": audio_base64,
6 "parameters": {
7 "max_length": 448,
8 "return_token_ids": True
9 }
10 }
11)1{
2 "error": "Error message here",
3 "status": "error",
4 "message": "An error occurred during transcription"
5}encoder_model.onnx + encoder_model.onnx_data - ONNX encoder (2.4GB)decoder_model.onnx + decoder_model.onnx_data - ONNX decoder (3.6GB)decoder_with_past_model.onnx + decoder_with_past_model.onnx_data - ONNX decoder with KV cache (3.2GB)tokenizer.json - Whisper tokenizerpreprocessor_config.json - Audio preprocessing configconfig.json - Model configurationgeneration_config.json - Generation parametershandler.py - Custom inference handlerrequirements.txt - Python dependencies1# Install Git LFS
2git lfs install
3
4# Clone your repository
5git clone https://huggingface.co/adithyafp/onnx-whisper-jv
6cd onnx-whisper-jv
7
8# Add all files
9git add .
10git commit -m "Add ONNX model with custom handler"
11git pushadithyafp/onnx-whisper-jv1import requests
2import base64
3
4# Your endpoint URL (from HF dashboard)
5ENDPOINT_URL = "https://xxxxxxxx.endpoints.huggingface.cloud"
6
7with open("test_audio.wav", "rb") as f:
8 audio_base64 = base64.b64encode(f.read()).decode()
9
10response = requests.post(
11 ENDPOINT_URL,
12 headers={"Authorization": "Bearer YOUR_HF_TOKEN"},
13 json={"inputs": audio_base64}
14)
15
16print(response.json())1from handler import EndpointHandler
2import base64
3
4# Initialize handler
5handler = EndpointHandler(path=".")
6
7# Load test audio
8with open("test_audio.wav", "rb") as f:
9 audio_bytes = f.read()
10
11audio_base64 = base64.b64encode(audio_bytes).decode()
12
13# Test inference
14result = handler({
15 "inputs": audio_base64,
16 "parameters": {"max_length": 448}
17})
18
19print(result)1onnxruntime>=1.16.0
2transformers>=4.30.0
3numpy>=1.24.0
4librosa>=0.10.0
5soundfile>=0.12.11@misc{whisper-jv-onnx-2024,
2 author = {adithyafp},
3 title = {ONNX Whisper Javanese ASR Model},
4 year = {2024},
5 publisher = {HuggingFace},
6 url = {https://huggingface.co/adithyafp/onnx-whisper-jv}
7}