rogerxavier
commited on
Commit
•
22f62ea
1
Parent(s):
733839a
Update 3mergeDialogToVideo.py
Browse files- 3mergeDialogToVideo.py +13 -11
3mergeDialogToVideo.py
CHANGED
@@ -152,18 +152,20 @@ def get_audio_data(text:str)-> "返回audio data io句柄, duration(也有可能
|
|
152 |
response = requests.post(url, headers=headers, data=ssml_text.encode('utf-8'))
|
153 |
|
154 |
if response.status_code == 200:
|
155 |
-
# print("音频持续时间是",response.audio_duration)
|
156 |
-
# print("音频数据是",response.content)
|
157 |
# 创建临时文件 -当前路径下面
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
|
|
|
|
|
|
|
|
167 |
|
168 |
else:
|
169 |
print("Error: Failed to synthesize audio. Status code:", response.status_code)
|
|
|
152 |
response = requests.post(url, headers=headers, data=ssml_text.encode('utf-8'))
|
153 |
|
154 |
if response.status_code == 200:
|
|
|
|
|
155 |
# 创建临时文件 -当前路径下面
|
156 |
+
try:
|
157 |
+
with tempfile.NamedTemporaryFile(dir='/mp3_out/',delete=False) as temp_file:
|
158 |
+
temp_file.write(response.content)
|
159 |
+
temp_file.close()
|
160 |
+
audio = MP3(temp_file.name)
|
161 |
+
# 获取音频时长(单位为秒)
|
162 |
+
audio_duration_seconds = audio.info.length #int即可
|
163 |
+
# 在这里完成您对文件的操作,比如返回文件名
|
164 |
+
file_name = temp_file.name
|
165 |
+
return file_name, audio_duration_seconds
|
166 |
+
except Exception as e:
|
167 |
+
print("可能遇到mp3 can not sync to MPEG frame错误,总之音频能获取到但是不能识别",e)
|
168 |
+
return None,None#这种也返回none告知错误不要管了
|
169 |
|
170 |
else:
|
171 |
print("Error: Failed to synthesize audio. Status code:", response.status_code)
|