Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,23 +5,18 @@ from acrcloud.recognizer import ACRCloudRecognizer
|
|
5 |
# Retrieve ACRCloud credentials from environment variables
|
6 |
acr_access_key = os.environ.get('ACR_ACCESS_KEY')
|
7 |
acr_access_secret = os.environ.get('ACR_ACCESS_SECRET')
|
8 |
-
acr_host =
|
9 |
-
|
10 |
-
# ACRCloud recognizer configuration
|
11 |
-
config = {
|
12 |
-
'host': acr_host,
|
13 |
-
'access_key': acr_access_key,
|
14 |
-
'access_secret': acr_access_secret,
|
15 |
-
'timeout': 10 # seconds
|
16 |
-
}
|
17 |
|
18 |
# Initialize ACRCloud recognizer
|
19 |
acr = ACRCloudRecognizer(config)
|
20 |
|
21 |
def identify_audio(file):
|
22 |
# Save the uploaded file temporarily
|
23 |
-
file_path = file.name
|
24 |
-
|
|
|
|
|
|
|
25 |
|
26 |
# Get the duration of the audio file in milliseconds
|
27 |
duration_ms = int(acr.get_duration_ms_by_file(file_path))
|
|
|
5 |
# Retrieve ACRCloud credentials from environment variables
|
6 |
acr_access_key = os.environ.get('ACR_ACCESS_KEY')
|
7 |
acr_access_secret = os.environ.get('ACR_ACCESS_SECRET')
|
8 |
+
acr_host = 'identify-ap-southeast-1.acrcloud.com'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
# Initialize ACRCloud recognizer
|
11 |
acr = ACRCloudRecognizer(config)
|
12 |
|
13 |
def identify_audio(file):
|
14 |
# Save the uploaded file temporarily
|
15 |
+
file_path = "temp_audio_file" + os.path.splitext(file.name)[-1] # Preserve the file extension
|
16 |
+
|
17 |
+
# Write the uploaded file to disk
|
18 |
+
with open(file_path, 'wb') as f:
|
19 |
+
f.write(file.file.read()) # Write the content of the uploaded file
|
20 |
|
21 |
# Get the duration of the audio file in milliseconds
|
22 |
duration_ms = int(acr.get_duration_ms_by_file(file_path))
|