Update app.py
Browse files
app.py
CHANGED
|
@@ -4,21 +4,24 @@ import datetime
|
|
| 4 |
import numpy as np
|
| 5 |
import hashlib
|
| 6 |
|
|
|
|
|
|
|
|
|
|
| 7 |
# Initialize a list to store file paths
|
| 8 |
uploaded_files = []
|
| 9 |
-
help_en = """
|
| 10 |
### Usage Instructions:
|
| 11 |
1. **Select a Label**: Choose a label from the dropdown menu, or select "Custom" to enter your own label.
|
| 12 |
2. **Enter User Name**: Input your user name, which will be used to generate a unique ID for your recordings.
|
| 13 |
-
3. **Record Audio**: Click the "Record Audio" button to start recording. The maximum length for each recording is
|
| 14 |
4. **Submit Recording**: After recording, click the "Submit" button to save the recording.
|
| 15 |
5. **Download Recordings**: Use the provided download links to retrieve all recorded files.
|
| 16 |
"""
|
| 17 |
-
help_zh_tw = """
|
| 18 |
### 使用流程:
|
| 19 |
1. **選擇標記**: 從下拉選單中選擇一個標記,或選擇“自定義”以輸入自己的標記。
|
| 20 |
2. **輸入用戶名稱**: 輸入您的用戶名稱,用於生成錄音唯一ID。
|
| 21 |
-
3. **錄製音頻**: 點擊“錄製音頻”按鈕開始錄音。每次錄音的最長時間為
|
| 22 |
4. **提交錄音**: 錄製完成後,點擊“提交”按鈕保存錄音。
|
| 23 |
5. **下載錄音**: 使用提供的下載鏈接下載所有已錄製的文件。
|
| 24 |
"""
|
|
@@ -42,10 +45,9 @@ def save_audio(audio, dropdown_label, custom_label, speaker_name):
|
|
| 42 |
# Calculate the audio length in seconds
|
| 43 |
audio_length = len(audio_data) / sample_rate
|
| 44 |
|
| 45 |
-
# Check if the audio length exceeds
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
raise gr.Error("Recording is longer than 1 second 💥!", duration=5)
|
| 49 |
|
| 50 |
# Generate speaker_id using a hash function to ensure consistency
|
| 51 |
speaker_id = hashlib.sha256(speaker_name.encode()).hexdigest()[:8]
|
|
@@ -82,7 +84,11 @@ def create_interface():
|
|
| 82 |
label_dropdown.change(toggle_custom_label, inputs=label_dropdown, outputs=custom_label)
|
| 83 |
|
| 84 |
speaker_name = gr.Textbox(label="Enter User Name")
|
| 85 |
-
audio = gr.Audio(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
submit_button = gr.Button("Submit")
|
| 88 |
|
|
|
|
| 4 |
import numpy as np
|
| 5 |
import hashlib
|
| 6 |
|
| 7 |
+
|
| 8 |
+
MAX_LENGTH = 1.5 # in seconds
|
| 9 |
+
|
| 10 |
# Initialize a list to store file paths
|
| 11 |
uploaded_files = []
|
| 12 |
+
help_en = f"""
|
| 13 |
### Usage Instructions:
|
| 14 |
1. **Select a Label**: Choose a label from the dropdown menu, or select "Custom" to enter your own label.
|
| 15 |
2. **Enter User Name**: Input your user name, which will be used to generate a unique ID for your recordings.
|
| 16 |
+
3. **Record Audio**: Click the "Record Audio" button to start recording. The maximum length for each recording is {MAX_LENGTH} second.
|
| 17 |
4. **Submit Recording**: After recording, click the "Submit" button to save the recording.
|
| 18 |
5. **Download Recordings**: Use the provided download links to retrieve all recorded files.
|
| 19 |
"""
|
| 20 |
+
help_zh_tw = f"""
|
| 21 |
### 使用流程:
|
| 22 |
1. **選擇標記**: 從下拉選單中選擇一個標記,或選擇“自定義”以輸入自己的標記。
|
| 23 |
2. **輸入用戶名稱**: 輸入您的用戶名稱,用於生成錄音唯一ID。
|
| 24 |
+
3. **錄製音頻**: 點擊“錄製音頻”按鈕開始錄音。每次錄音的最長時間為{MAX_LENGTH}秒。
|
| 25 |
4. **提交錄音**: 錄製完成後,點擊“提交”按鈕保存錄音。
|
| 26 |
5. **下載錄音**: 使用提供的下載鏈接下載所有已錄製的文件。
|
| 27 |
"""
|
|
|
|
| 45 |
# Calculate the audio length in seconds
|
| 46 |
audio_length = len(audio_data) / sample_rate
|
| 47 |
|
| 48 |
+
# Check if the audio length exceeds MAX_LENGTH second
|
| 49 |
+
if audio_length > MAX_LENGTH:
|
| 50 |
+
raise gr.Error(f"Recording is longer than {MAX_LENGTH} second 💥!", duration=5)
|
|
|
|
| 51 |
|
| 52 |
# Generate speaker_id using a hash function to ensure consistency
|
| 53 |
speaker_id = hashlib.sha256(speaker_name.encode()).hexdigest()[:8]
|
|
|
|
| 84 |
label_dropdown.change(toggle_custom_label, inputs=label_dropdown, outputs=custom_label)
|
| 85 |
|
| 86 |
speaker_name = gr.Textbox(label="Enter User Name")
|
| 87 |
+
audio = gr.Audio(
|
| 88 |
+
sources=["microphone", "upload"],
|
| 89 |
+
type="numpy",
|
| 90 |
+
label="Record Audio"
|
| 91 |
+
)
|
| 92 |
|
| 93 |
submit_button = gr.Button("Submit")
|
| 94 |
|