如何将从S3下载的WAV文件保存到文件

时间:2018-12-26 16:35:43

标签: python amazon-s3 wav

我在s3中保存了一个音频wav文件。我使用以下代码下载它:

    s3 = boto3.resource('s3')
    s3_object = s3.Object(
        bucket_name=bucket_name,
        key=self.s3_key(s3_key),
    ).get()
    audio_data = s3_object['Body'].read()

现在,我想将数据保存到.wav文件中,以便稍后阅读和播放。该怎么办?

2 个答案:

答案 0 :(得分:1)

  

尝试 download_file

import boto3
s3 = boto3.client('s3', aws_access_key_id=... , aws_secret_access_key=...)
s3.download_file('your_bucket','k.png','/Users/username/Desktop/k.png')

答案 1 :(得分:0)

您需要将二进制数据保存到文件中。例如:

 'Current List Template
    Dim cbook As Workbook
    Set cbook = ActiveWorkbook


    'Prior List Template
    Dim pbook As Workbook
    'Workbook
   ' Set pbook = Workbooks.Open(JRDCPriorNoBrk)

    cbook.Activate


    '********************
    'Turns off screen updates (no flashes)
    '********************
    With Application
        '.Calculation = xlCalculationManual
        .ScreenUpdating = False
    End With




    'Make sure user is on JobReq & DataChg INST tab to run macro
    Sheets("JobReq & DataChg INST").Activate


    'unshare the workbook to run macro
    'ActiveWorkbook.SaveAs ActiveWorkbook.FullName, accessmode:=xlExclusive
    Application.DisplayAlerts = False
   ' ActiveWorkbook.ExclusiveAccess


For Each xworksheet In ActiveWorkbook.Worksheets

    xworksheet.Activate

If ActiveSheet.Name = "Original" Or ActiveSheet.Name = "JobReq & DataChg INST" Then GoTo NotThisSheet

    'unprotects sheets so user can run macro
    ActiveSheet.Unprotect


    'ActiveSheet.Range("AG2").Select

    Dim Srng As Range
    Dim LastRow As Long

    'Set Srng = Worksheets("Coniguration").Range("_Configuration")
    'Set Srng = ActiveSheet.Range("AF2:AJ18")

    'pbook.Worksheet (cbook.ActiveSheet.Name)
     'LastRowp = .Cells(.Rows.Count, "AF").End(xlUp).Row


     'Set Srng = pbook.Worksheet(ActiveSheet.Name)
     'Set Srng = PathJRDCPrior.ActiveSheet.Range("AF2:AJ" & LastRowp)





    With ActiveSheet


     'With pbook.Worksheets(cbook.ActiveSheet.Name)
    'With Worksheets(" & PathJRDCPrior & ")
        'current worksheet last row
        LastRow = .Cells(.Rows.Count, "AF").End(xlUp).Row

        'prior worksheet last row
        'MsgBox (cbook.ActiveSheet.Name)
        With pbook.Worksheets(cbook.ActiveSheet.Name)
        'pbook.Worksheets (cbook.ActiveSheet.Name)
        LastRowp = .Cells(.Rows.Count, "AF").End(xlUp).Row
        SSheet = cbook.ActiveSheet.Name
        Set SPath = PathJRDCPrior

        'Set Srng = PathJRDCPrior.ActiveSheet.Range("AF2:AJ" & LastRowp)
        'Srng = pbook.Worksheets(cbook.ActiveSheet.Name).Range("AF2:AJ" & LastRowp)
        Set Srng = Worksheets(SSheet).Range("AF2:AJ" & LastRowp)
        End With
       ' MsgBox (Srng)

        With cbook.ActiveSheet.Range("AG2:AG" & LastRow)
                   With cbook.ActiveSheet.Range("AG2:AG" & LastRow)
            **.FormulaR1C1 = "=VLOOKUP(RC32," & Srng.Address(, , xlR1C1, True) & ", 2, 0)"**


            .Value = .Value
        End With
        With cbook.ActiveSheet.Range("AH2:AH" & LastRow)
            .FormulaR1C1 = "=VLOOKUP(RC32," & Srng.Address(, , xlR1C1, True) & ", 3, 0)"
            .Value = .Value
        End With
        With cbook.ActiveSheet.Range("AI2:AI" & LastRow)
            .FormulaR1C1 = "=VLOOKUP(RC32," & Srng.Address(, , xlR1C1, True) & ", 4, 0)"
            .Value = .Value
        End With
        With cbook.ActiveSheet.Range("AJ2:AJ" & LastRow)
            .FormulaR1C1 = "=VLOOKUP(RC32," & Srng.Address(, , xlR1C1, True) & ", 5, 0)"
            .Value = .Value
        End With
           End With

NotThisSheet:
Next xworksheet

'share workbook
ActiveWorkbook.SaveAs ActiveWorkbook.FullName, accessmode:=xlShared
Application.DisplayAlerts = True

MsgBox ("Copying from the prior list is complete.")

End Sub