0

I am new in Azure cloud. Now I hope to create a work flow: upload a audio file to the blob --> Blob trigger is invoked --> deployed python function read the upload audio file and extract harmonics --> harmonics output as json file and save in another container. Blow is my code but it doesn't work:

import logging
import azure.function as func
import audio_read

def main(myblob: func.InputStream):

    logging.info(f"Python blob trigger function processed blob \n"
                 f"Name: {myblob.name}\n"
                 f"Blob Size: {myblob.length} bytes")
    
    audio_info = audioread.audio_open(myblob.read())
    logging.info(f"{audio_info}")

It returns me an error:

Exception: UnicodeDecodeError: "utf-8" codec can't decode byte 0x80 in position 40: invalid start byte.

my function.json is:

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "myblob",
      "type": "blobTrigger",
      "direction": "in",
      "path": "examplecontainer/{name}",
      "connection": "AzureWebJobsStorage"
    }
  ]
}
tlentali
  • 3,407
  • 2
  • 14
  • 21
  • https://stackoverflow.com/questions/38518023/unicodedecodeerror-utf8-codec-cant-decode-byte-0x80-in-position-3131-invali – codebrane Nov 05 '21 at 14:21
  • Why when I run the code locally (audioread.audio_open("File saved path"), there is no error? However once I run on Azure Function (audioread.audio_open("inputblob"), it doesnt work. Is the way I feed blob wrong? – user14834847 Nov 06 '21 at 07:04
  • Make sure to upload your audio files as Blobs that contain binary data with proper ```content type``` and ```content encoding```, see [documentation](https://learn.microsoft.com/en-us/python/api/azure-storage-blob/azure.storage.blob.models.contentsettings?view=azure-python-previous) – Anand Sowmithiran Nov 08 '21 at 07:29

1 Answers1

-1

The input binding allows you to read blob storage data as input to an Azure Function.

For more details refer this document : https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob-input?tabs=python

And make sure that you have given the proper content type and encoding while uploading audio file as blob in azure storage

For more details refer this document

ShrutiJoshi-MT
  • 1,622
  • 1
  • 4
  • 9