File size: 1,278 Bytes
298dc4e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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}")