添加换行符,让显示更直观
This commit is contained in:
parent
564c08c944
commit
115fe1033e
@ -23,7 +23,7 @@ local function convertAndPlay()
|
||||
-- ===== 3. 错误处理 / Error handling =====
|
||||
-- 网络错误 / Network error
|
||||
if not response then
|
||||
printError("HTTP request failed: " .. (err or "unknown error"))
|
||||
printError("\nHTTP request failed: " .. (err or "unknown error"))
|
||||
return
|
||||
end
|
||||
|
||||
@ -34,27 +34,27 @@ local function convertAndPlay()
|
||||
-- HTTP状态码检查 / HTTP status check
|
||||
local statusCode = response.getResponseCode()
|
||||
if statusCode ~= 200 then
|
||||
printError("API error (status "..statusCode..")")
|
||||
printError("\nAPI error (status "..statusCode..")")
|
||||
return
|
||||
end
|
||||
|
||||
-- ===== 4. 解析JSON / Parse JSON =====
|
||||
local responseData = textutils.unserializeJSON(responseBody)
|
||||
if not responseData then
|
||||
printError("Invalid API response (bad JSON)")
|
||||
printError("\nInvalid API response (bad JSON)")
|
||||
return
|
||||
end
|
||||
|
||||
-- API业务错误 / API logic error
|
||||
if responseData.status ~= "success" then
|
||||
printError("Conversion failed: "..(responseData.error or "no error info"))
|
||||
printError("\nConversion failed: "..(responseData.error or "no error info"))
|
||||
return
|
||||
end
|
||||
|
||||
-- ===== 5. 播放音频 / Play audio =====
|
||||
print("Conversion successful! Download URL:")
|
||||
print("\nConversion successful! Download URL:")
|
||||
print(responseData.download_url)
|
||||
print("Playing...")
|
||||
print("\nPlaying...")
|
||||
shell.run("speaker play "..responseData.download_url)
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user