iOS 上的 AWS Transcribe 错误:找不到具有指定主机名的服务器

AWS Transcribe error on iOS: A server with the specified hostname could not be found

下面的代码在 iOS 上使用 AWS Transcribe 生成此错误:

Task <1B377509-91AE-43C0-8F24-F28FE7B583AC>.<1> load failed with error Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found." UserInfo={_kCFStreamErrorCodeKey=8, NSUnderlyingError=0x283cb55f0 {Error Domain=kCFErrorDomainCFNetwork Code=-1003 "(null)" UserInfo={_kCFStreamErrorCodeKey=8, _kCFStreamErrorDomainKey=12}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <1B377509-91AE-43C0-8F24-F28FE7B583AC>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=( "LocalDataTask <1B377509-91AE-43C0-8F24-F28FE7B583AC>.<1>" ), NSLocalizedDescription=A server with the specified hostname could not be found., NSErrorFailingURLStringKey=https://transcribe.us-west-1.amazonaws.com/, NSErrorFailingURLKey=https://transcribe.us-west-1.amazonaws.com/, _kCFStreamErrorDomainKey=12} [-1003]

US-West1 是 AWS Transcribe 支持的区域。为什么会出现此错误?

class TranscriptionNewViewController: UIViewController {


    override func viewDidLoad() {
        super.viewDidLoad()
    }


    // =============================================================================================================
    // MARK: Transcription Functions
    // =============================================================================================================
    fileprivate func transcribe() {
        let fileURL = "https://s3-us-west-2.amazonaws.com/blahblahblah/Sample1.mp3"

        let jobName = "sample1"
        let languageCode = AWSTranscribeLanguageCode.enUS
        let mediaFormat = AWSTranscribeMediaFormat.mp3
        let media = AWSTranscribeMedia()
        media?.mediaFileUri = fileURL

        let jobRequest = AWSTranscribeStartTranscriptionJobRequest()
        jobRequest?.transcriptionJobName = jobName
        jobRequest?.languageCode = languageCode
        jobRequest?.mediaFormat = mediaFormat
        jobRequest?.media = media

        let transcribeClient = AWSTranscribe.default()

        DispatchQueue.global(qos: .background).async {
            transcribeClient.startTranscriptionJob(jobRequest!) { response, error in
                guard let response = response else {
                    print("Failed to start transcription")
                    return
                }

                print(response.transcriptionJob!.transcriptionJobStatus == .inProgress, "Status should have been in progress, but was \(response.transcriptionJob!.transcriptionJobStatus)")

                self.transcribeJobDidFinish()
            }
        }

        // Print status
        print("Started transcription")
    }


    fileprivate func transcribeJobDidFinish() {

    }


    // =============================================================================================================
    // MARK: IB Actions
    // =============================================================================================================
    @IBAction func transcribeButtonDidTap(_ sender: UIButton) {
        transcribe()
    }


    // =============================================================================================================
    // MARK: UIViewController Functions
    // =============================================================================================================
    override var prefersStatusBarHidden: Bool {
        return true
    }


    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}

目前只有美国西部的us-west-2个aws区域提供AWS Transcribe服务。 us-west-1 不是其中之一,这是您收到主机名查找错误的原因。

大多数服务的可用端点的完整列表可以在 https://docs.aws.amazon.com/general/latest/gr/rande.html 中找到,特别是在 Amazon Transcribe 标题下。