D-ID API:PENDEND_URL成功发布后返回而不是视频URL 使用D-ID API时,我会遇到pending_url问题。 我正在提出邮政请求来创建谈话,该会谈返回201个状态代码和谈话ID。 之后,我立即提出请求

问题描述 投票:0回答:0

pending_url

post请求成功(201),并且响应包含谈话ID。但是,随后的GET请求返回带有A的响应,并且
@app.route('/video') def video(): # retrieve the value of the environment variable named DID_API_KEY from .env did_api_key = os.getenv('DID_API_KEY') if len(did_api_key) != None: print("The function load_dotenv() has loaded the DID_API_KEY correctly.") print("The value of the did_api_key is: ", did_api_key) else: print("Problem loading the DID_API_KEY. Please review .env file.") return "Problem loading the DID_API_KEY. Please review .env file." # retrieve the value of the environment variable named BEARER_TOKEN from .env bearer_token = os.getenv('BEARER_TOKEN') if len(bearer_token) != None: print("The function load_dotenv() has loaded the BEARER_TOKEN correctly.") print("The value of the bearer_key is: ", bearer_token) else: print("Problem loading the BEARER_TOKEN. Please review .env file.") return "Problem loading the BEARER_TOKEN. Please review .env file." # Create a talk POST # DID_API_KEY obtained. Use it to generate the AI Talking Avatar. import requests url = "https://api.d-id.com/talks" source_url = "https://i.imghippo.com/files/wHD7943BS.jpg" input_text = "Making videos is easy with D-ID" payload = { "source_url": source_url, "script": { "type": "text", "subtitles": "false", "provider": { "type": "microsoft", "voice_id": "Sara" }, "input": input_text }, "config": { "fluent": "false", "pad_audio": "0.0" } } headers = { "accept": "application/json", "content-type": "application/json", "authorization": "Bearer {0}".format(bearer_token) } response = requests.post(url, json=payload, headers=headers) if response.status_code == 402: # not enough d-id api credits # response.text = {"kind":"InsufficientCreditsError","description":"not enough credits"} 402 return '>>> ' + response.text + ' ' + str(response.status_code) if response.status_code == 201: # got a 201 after a POST request, it's a positive sign. # It confirms that the server has successfully created the resource. print(response.text) print(response.status_code) """ { "id":"tlk_pCB0A1dMhZi0JfA0S8NE5", "created_at":"2025-02-03T20:02:39.302Z", "created_by":"google-oauth2|103344389677485792824", "status":"created", "object":"talk" } response.status_code equals 201 """ # get a specific talk GET print("get a specific talk GET") # get the id of the video id_video = response.json()["id"] headers = { "accept": "application/json", "authorization": "Bearer {0}".format(bearer_token) } # set url url = "https://api.d-id.com/talks/{0}".format(id_video) response = requests.get(url, headers=headers) print(response.text) print(response.status_code) return response.text
pending_url
,表明视频处理尚未完成。 预期的行为是因为GET请求最终在处理完成后返回适当的视频URL。 there是我收到的获取响应的一个例子:

status

我已经检查了我的
started

{ "user": { "features": ["stitch", "clips:write", "scene", "premium-plus:skip-speaker-validation", null], "stripe_plan_group": "deid-trial", "authorizer": "bearer", "org_id": null, "owner_id": "auth0|67a12d64c60b14766a228fda", "domain": "https://studio.d-id.com", "id": "auth0|67a12d64c60b14766a228fda", "plan": "deid-trial", "email": "[email protected]" }, "script": { "length": 31, "subtitles": false, "type": "text", "provider": { "type": "microsoft", "voice_id": "Sara" } }, "audio_url": "https://d-id-talks-prod.s3.us-west-2.amazonaws.com/auth0%7C67a12d64c60b14766a228fda/tlk_dhNTB5cDt-aBHUGoqN0jf/microsoft.wav?AWSAccessKeyId=AKIA5CUMPJBIK65W6FGA&Expires=1738704589&Signature=%2F3lSL1GS%2FkgK%2FH1nlLAkVYSG3rw%3D", "created_at": "2025-02-03T21:29:49.187Z", "config": { "stitch": false, "pad_audio": 0, "align_driver": true, "sharpen": true, "reduce_noise": false, "auto_match": true, "normalization_factor": 1, "show_watermark": true, "motion_factor": 1, "result_format": ".mp4", "fluent": false, "align_expand_factor": 0.3 }, "source_url": "https://d-id-talks-prod.s3.us-west-2.amazonaws.com/auth0%7C67a12d64c60b14766a228fda/tlk_dhNTB5cDt-aBHUGoqN0jf/source/wHD7943BS.jpg?AWSAccessKeyId=AKIA5CUMPJBIK65W6FGA&Expires=1738704589&Signature=xY6c9d57Xy1gOnUhAJWK7zUtWXY%3D", "created_by": "auth0|67a12d64c60b14766a228fda", "status": "started", "driver_url": "bank://natural/", "modified_at": "2025-02-03T21:29:49.476Z", "user_id": "auth0|67a12d64c60b14766a228fda", "subtitles": false, "id": "tlk_dhNTB5cDt-aBHUGoqN0jf", "duration": 2.4625, "started_at": "2025-02-03T21:29:49.239", "pending_url": "s3://d-id-talks-prod/auth0|67a12d64c60b14766a228fda/tlk_dhNTB5cDt-aBHUGoqN0jf/1738618189187.mp4" }

,它们是正确的。  处理完成后,如何正确检索最终视频URL?  我应该使用轮询机制或Webhook吗?  使用D-ID API处理异步视频处理的推荐方法是什么?
    
发现解决方案,以下是技术细节:
API民意调查:该代码使用一个WARE循环将GET请求发送到API,直到视频响应状态“完成”为止。这是API投票的一个示例,可用于等待长期运行的过程完成。该循环在此代码段中至关重要,因为它实现了一种称为民意调查或忙碌等待的技术。该技术用于等待满足特定条件,在这种情况下,服务器以“完成”状态响应。

完整的代码是:

BEARER_TOKEN
    

python flask
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.