File size: 1,386 Bytes
7dde9f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
39
40
41
import requests
import os

# The URL of the pronunciation scoring API
url = "https://huggingface.co/spaces/Kartikeyssj2/pronunciation-scoring/pronunciation_scoring"

# Path to your audio file
audio_file_path = "D:\Freelancing\AI Feature Scoring\deployed endpoints\Pronunciation\Pronunciation_Scoring\pronunciation-scoring\WhatsApp Audio 2024-07-08 at 21.18.00_659e4840.waptt.opus"  # Replace with the actual path to your audio file

# Check if the file exists
if not os.path.exists(audio_file_path):
    print(f"Error: The file {audio_file_path} does not exist.")
    exit(1)

# Prepare the files for the POST request
files = {
    "audio_file": open(audio_file_path, 'rb')
}

try:
    # Make the POST request
    audio_file = open(audio_file_path , "rb")
    print(audio_file)
    response = requests.post(url, file = audio_file)

    # Check if the request was successful
    if response.status_code == 200:
        # Parse the JSON response
        result = response.json()
        print("Transcription:", result["transcription"])
        print("Pronunciation Score:", result["pronunciation_score"])
    else:
        print(f"Error: Received status code {response.status_code}")
        print(response.text)

except requests.exceptions.RequestException as e:
    print(f"An error occurred while making the request: {e}")

finally:
    # Close the file
    files['audio_file'].close()