semabox / usage /python.py
Tri4's picture
Create usage/python.py
298dc4e verified
import requests
# API endpoint - https://tri4-semalab.hf.space/
url = "https://jikoni-semabox.hf.space/transcribe"
# Path to the audio file you want to transcribe
audio_file_path = "/content/audio_samples/sample7.wav"
#audio_file_path ="/content/audio_samples/audio_file_test.wav"
# Open the audio file in binary mode
try:
with open(audio_file_path, 'rb') as audio_file:
# Prepare the files dictionary with the 'audio' key
files = {
'audio': audio_file
}
# Send a POST request to the API
response = requests.post(url, files=files)
# Check if the request was successful
if response.status_code == 200:
# Print the JSON response containing the transcription
print(response.json())
# Extract the transcription from the JSON response
transcription = response.json().get('transcription', '')
print(f"\nTranscription: {transcription}")
else:
# Print the error if the request was not successful
print(f"Error: {response.status_code}, {response.text}")
except FileNotFoundError:
print(f"Error: The file {audio_file_path} was not found.")
except requests.RequestException as e:
print(f"Request error: {e}")