rogerxavier
commited on
Commit
•
969c412
1
Parent(s):
d984987
Update 3mergeDialogToVideo.py
Browse files- 3mergeDialogToVideo.py +7 -1
3mergeDialogToVideo.py
CHANGED
@@ -21,6 +21,9 @@ from io import BytesIO
|
|
21 |
import pandas as pd
|
22 |
from PIL import Image
|
23 |
import os
|
|
|
|
|
|
|
24 |
azure_speech_key = os.getenv('azure_speech_key')
|
25 |
azure_service_region = os.getenv('azure_service_region')
|
26 |
my_openai_key = os.getenv('my_openai_key')
|
@@ -149,9 +152,12 @@ def get_audio_data(text:str)-> "返回audio data io句柄, duration":
|
|
149 |
with tempfile.NamedTemporaryFile(dir='/',delete=False) as temp_file:
|
150 |
temp_file.write(response.content)
|
151 |
temp_file.close()
|
|
|
|
|
|
|
152 |
# 在这里完成您对文件的操作,比如返回文件名
|
153 |
file_name = temp_file.name
|
154 |
-
return file_name,
|
155 |
|
156 |
else:
|
157 |
print("Error: Failed to synthesize audio. Status code:", response.status_code)
|
|
|
21 |
import pandas as pd
|
22 |
from PIL import Image
|
23 |
import os
|
24 |
+
from mutagen.mp3 import MP3 #读取音频获取时长
|
25 |
+
|
26 |
+
|
27 |
azure_speech_key = os.getenv('azure_speech_key')
|
28 |
azure_service_region = os.getenv('azure_service_region')
|
29 |
my_openai_key = os.getenv('my_openai_key')
|
|
|
152 |
with tempfile.NamedTemporaryFile(dir='/',delete=False) as temp_file:
|
153 |
temp_file.write(response.content)
|
154 |
temp_file.close()
|
155 |
+
audio = MP3(temp_file.name)
|
156 |
+
# 获取音频时长(单位为秒)
|
157 |
+
audio_duration_seconds = audio.info.length #int即可
|
158 |
# 在这里完成您对文件的操作,比如返回文件名
|
159 |
file_name = temp_file.name
|
160 |
+
return file_name, audio_duration_seconds
|
161 |
|
162 |
else:
|
163 |
print("Error: Failed to synthesize audio. Status code:", response.status_code)
|