prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  opus decoding error
  see https://huggingface.co/datasets/stable-speech/mls_eng_10k/discussions/1#65ef6e9d440a5fc3d94a40ad
  
  To fix this maybe we should pin `soundfile` library to `>=1.0.31` (first version that supported opus) like [we do in `datasets` library](https://github.com/huggingface/datasets/blob/main/src/datasets/config.py#L144). 
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `libs/libcommon/src/libcommon/viewer_utils/asset.py`
  Content:
  ```
  1 # SPDX-License-Identifier: Apache-2.0
  2 # Copyright 2022 The HuggingFace Authors.
  3 
  4 from io import BytesIO
  5 from pathlib import Path
  6 from tempfile import NamedTemporaryFile
  7 from typing import Optional, TypedDict
  8 from urllib import parse
  9 
  10 from PIL import Image, ImageOps
  11 from pydub import AudioSegment  # type:ignore
  12 
  13 from libcommon.constants import DATASET_SEPARATOR
  14 from libcommon.storage import StrPath, remove_dir
  15 from libcommon.storage_client import StorageClient
  16 
  17 SUPPORTED_AUDIO_EXTENSION_TO_MEDIA_TYPE = {".wav": "audio/wav", ".mp3": "audio/mpeg"}
  18 
  19 
  20 def delete_asset_dir(dataset: str, directory: StrPath) -> None:
  21     dir_path = Path(directory).resolve() / dataset
  22     remove_dir(dir_path)
  23 
  24 
  25 class ImageSource(TypedDict):
  26     src: str
  27     height: int
  28     width: int
  29 
  30 
  31 class AudioSource(TypedDict):
  32     src: str
  33     type: str
  34 
  35 
  36 def generate_object_key(
  37     dataset: str, revision: str, config: str, split: str, row_idx: int, column: str, filename: str
  38 ) -> str:
  39     return f"{parse.quote(dataset)}/{DATASET_SEPARATOR}/{revision}/{DATASET_SEPARATOR}/{parse.quote(config)}/{parse.quote(split)}/{str(row_idx)}/{parse.quote(column)}/{filename}"
  40 
  41 
  42 def create_image_file(
  43     dataset: str,
  44     revision: str,
  45     config: str,
  46     split: str,
  47     row_idx: int,
  48     column: str,
  49     filename: str,
  50     image: Image.Image,
  51     format: str,
  52     storage_client: StorageClient,
  53 ) -> ImageSource:
  54     object_key = generate_object_key(
  55         dataset=dataset,
  56         revision=revision,
  57         config=config,
  58         split=split,
  59         row_idx=row_idx,
  60         column=column,
  61         filename=filename,
  62     )
  63     if storage_client.overwrite or not storage_client.exists(object_key):
  64         image = ImageOps.exif_transpose(image)  # type: ignore[assignment]
  65         buffer = BytesIO()
  66         image.save(fp=buffer, format=format)
  67         buffer.seek(0)
  68         with storage_client._fs.open(storage_client.get_full_path(object_key), "wb") as f:
  69             f.write(buffer.read())
  70     return ImageSource(src=storage_client.get_url(object_key), height=image.height, width=image.width)
  71 
  72 
  73 def create_audio_file(
  74     dataset: str,
  75     revision: str,
  76     config: str,
  77     split: str,
  78     row_idx: int,
  79     column: str,
  80     audio_file_bytes: bytes,
  81     audio_file_extension: Optional[str],
  82     filename: str,
  83     storage_client: StorageClient,
  84 ) -> list[AudioSource]:
  85     object_key = generate_object_key(
  86         dataset=dataset,
  87         revision=revision,
  88         config=config,
  89         split=split,
  90         row_idx=row_idx,
  91         column=column,
  92         filename=filename,
  93     )
  94     suffix = f".{filename.split('.')[-1]}"
  95     if suffix not in SUPPORTED_AUDIO_EXTENSION_TO_MEDIA_TYPE:
  96         raise ValueError(
  97             f"Audio format {suffix} is not supported. Supported formats are"
  98             f" {','.join(SUPPORTED_AUDIO_EXTENSION_TO_MEDIA_TYPE)}."
  99         )
  100     media_type = SUPPORTED_AUDIO_EXTENSION_TO_MEDIA_TYPE[suffix]
  101 
  102     if storage_client.overwrite or not storage_client.exists(object_key):
  103         audio_path = storage_client.get_full_path(object_key)
  104         if audio_file_extension == suffix:
  105             with storage_client._fs.open(audio_path, "wb") as f:
  106                 f.write(audio_file_bytes)
  107         else:  # we need to convert
  108             # might spawn a process to convert the audio file using ffmpeg
  109             with NamedTemporaryFile("wb", suffix=audio_file_extension) as tmpfile:
  110                 tmpfile.write(audio_file_bytes)
  111                 segment: AudioSegment = AudioSegment.from_file(
  112                     tmpfile.name, audio_file_extension[1:] if audio_file_extension else None
  113                 )
  114                 buffer = BytesIO()
  115                 segment.export(buffer, format=suffix[1:])
  116                 buffer.seek(0)
  117                 with storage_client._fs.open(audio_path, "wb") as f:
  118                     f.write(buffer.read())
  119     return [AudioSource(src=storage_client.get_url(object_key), type=media_type)]
  120
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/libs/libcommon/src/libcommon/viewer_utils/asset.py b/libs/libcommon/src/libcommon/viewer_utils/asset.py
  --- a/libs/libcommon/src/libcommon/viewer_utils/asset.py
  +++ b/libs/libcommon/src/libcommon/viewer_utils/asset.py
  @@ -108,9 +108,7 @@
               # might spawn a process to convert the audio file using ffmpeg
               with NamedTemporaryFile("wb", suffix=audio_file_extension) as tmpfile:
                   tmpfile.write(audio_file_bytes)
  -                segment: AudioSegment = AudioSegment.from_file(
  -                    tmpfile.name, audio_file_extension[1:] if audio_file_extension else None
  -                )
  +                segment: AudioSegment = AudioSegment.from_file(tmpfile.name)
                   buffer = BytesIO()
                   segment.export(buffer, format=suffix[1:])
                   buffer.seek(0)
  
verification_info: {"golden_diff": "diff --git a/libs/libcommon/src/libcommon/viewer_utils/asset.py b/libs/libcommon/src/libcommon/viewer_utils/asset.py\n--- a/libs/libcommon/src/libcommon/viewer_utils/asset.py\n+++ b/libs/libcommon/src/libcommon/viewer_utils/asset.py\n@@ -108,9 +108,7 @@\n             # might spawn a process to convert the audio file using ffmpeg\n             with NamedTemporaryFile(\"wb\", suffix=audio_file_extension) as tmpfile:\n                 tmpfile.write(audio_file_bytes)\n-                segment: AudioSegment = AudioSegment.from_file(\n-                    tmpfile.name, audio_file_extension[1:] if audio_file_extension else None\n-                )\n+                segment: AudioSegment = AudioSegment.from_file(tmpfile.name)\n                 buffer = BytesIO()\n                 segment.export(buffer, format=suffix[1:])\n                 buffer.seek(0)\n", "issue": "opus decoding error\nsee https://huggingface.co/datasets/stable-speech/mls_eng_10k/discussions/1#65ef6e9d440a5fc3d94a40ad\r\n\r\nTo fix this maybe we should pin `soundfile` library to `>=1.0.31` (first version that supported opus) like [we do in `datasets` library](https://github.com/huggingface/datasets/blob/main/src/datasets/config.py#L144). \r\n\n", "before_files": [{"content": "# SPDX-License-Identifier: Apache-2.0\n# Copyright 2022 The HuggingFace Authors.\n\nfrom io import BytesIO\nfrom pathlib import Path\nfrom tempfile import NamedTemporaryFile\nfrom typing import Optional, TypedDict\nfrom urllib import parse\n\nfrom PIL import Image, ImageOps\nfrom pydub import AudioSegment  # type:ignore\n\nfrom libcommon.constants import DATASET_SEPARATOR\nfrom libcommon.storage import StrPath, remove_dir\nfrom libcommon.storage_client import StorageClient\n\nSUPPORTED_AUDIO_EXTENSION_TO_MEDIA_TYPE = {\".wav\": \"audio/wav\", \".mp3\": \"audio/mpeg\"}\n\n\ndef delete_asset_dir(dataset: str, directory: StrPath) -> None:\n    dir_path = Path(directory).resolve() / dataset\n    remove_dir(dir_path)\n\n\nclass ImageSource(TypedDict):\n    src: str\n    height: int\n    width: int\n\n\nclass AudioSource(TypedDict):\n    src: str\n    type: str\n\n\ndef generate_object_key(\n    dataset: str, revision: str, config: str, split: str, row_idx: int, column: str, filename: str\n) -> str:\n    return f\"{parse.quote(dataset)}/{DATASET_SEPARATOR}/{revision}/{DATASET_SEPARATOR}/{parse.quote(config)}/{parse.quote(split)}/{str(row_idx)}/{parse.quote(column)}/{filename}\"\n\n\ndef create_image_file(\n    dataset: str,\n    revision: str,\n    config: str,\n    split: str,\n    row_idx: int,\n    column: str,\n    filename: str,\n    image: Image.Image,\n    format: str,\n    storage_client: StorageClient,\n) -> ImageSource:\n    object_key = generate_object_key(\n        dataset=dataset,\n        revision=revision,\n        config=config,\n        split=split,\n        row_idx=row_idx,\n        column=column,\n        filename=filename,\n    )\n    if storage_client.overwrite or not storage_client.exists(object_key):\n        image = ImageOps.exif_transpose(image)  # type: ignore[assignment]\n        buffer = BytesIO()\n        image.save(fp=buffer, format=format)\n        buffer.seek(0)\n        with storage_client._fs.open(storage_client.get_full_path(object_key), \"wb\") as f:\n            f.write(buffer.read())\n    return ImageSource(src=storage_client.get_url(object_key), height=image.height, width=image.width)\n\n\ndef create_audio_file(\n    dataset: str,\n    revision: str,\n    config: str,\n    split: str,\n    row_idx: int,\n    column: str,\n    audio_file_bytes: bytes,\n    audio_file_extension: Optional[str],\n    filename: str,\n    storage_client: StorageClient,\n) -> list[AudioSource]:\n    object_key = generate_object_key(\n        dataset=dataset,\n        revision=revision,\n        config=config,\n        split=split,\n        row_idx=row_idx,\n        column=column,\n        filename=filename,\n    )\n    suffix = f\".{filename.split('.')[-1]}\"\n    if suffix not in SUPPORTED_AUDIO_EXTENSION_TO_MEDIA_TYPE:\n        raise ValueError(\n            f\"Audio format {suffix} is not supported. Supported formats are\"\n            f\" {','.join(SUPPORTED_AUDIO_EXTENSION_TO_MEDIA_TYPE)}.\"\n        )\n    media_type = SUPPORTED_AUDIO_EXTENSION_TO_MEDIA_TYPE[suffix]\n\n    if storage_client.overwrite or not storage_client.exists(object_key):\n        audio_path = storage_client.get_full_path(object_key)\n        if audio_file_extension == suffix:\n            with storage_client._fs.open(audio_path, \"wb\") as f:\n                f.write(audio_file_bytes)\n        else:  # we need to convert\n            # might spawn a process to convert the audio file using ffmpeg\n            with NamedTemporaryFile(\"wb\", suffix=audio_file_extension) as tmpfile:\n                tmpfile.write(audio_file_bytes)\n                segment: AudioSegment = AudioSegment.from_file(\n                    tmpfile.name, audio_file_extension[1:] if audio_file_extension else None\n                )\n                buffer = BytesIO()\n                segment.export(buffer, format=suffix[1:])\n                buffer.seek(0)\n                with storage_client._fs.open(audio_path, \"wb\") as f:\n                    f.write(buffer.read())\n    return [AudioSource(src=storage_client.get_url(object_key), type=media_type)]\n", "path": "libs/libcommon/src/libcommon/viewer_utils/asset.py"}], "after_files": [{"content": "# SPDX-License-Identifier: Apache-2.0\n# Copyright 2022 The HuggingFace Authors.\n\nfrom io import BytesIO\nfrom pathlib import Path\nfrom tempfile import NamedTemporaryFile\nfrom typing import Optional, TypedDict\nfrom urllib import parse\n\nfrom PIL import Image, ImageOps\nfrom pydub import AudioSegment  # type:ignore\n\nfrom libcommon.constants import DATASET_SEPARATOR\nfrom libcommon.storage import StrPath, remove_dir\nfrom libcommon.storage_client import StorageClient\n\nSUPPORTED_AUDIO_EXTENSION_TO_MEDIA_TYPE = {\".wav\": \"audio/wav\", \".mp3\": \"audio/mpeg\"}\n\n\ndef delete_asset_dir(dataset: str, directory: StrPath) -> None:\n    dir_path = Path(directory).resolve() / dataset\n    remove_dir(dir_path)\n\n\nclass ImageSource(TypedDict):\n    src: str\n    height: int\n    width: int\n\n\nclass AudioSource(TypedDict):\n    src: str\n    type: str\n\n\ndef generate_object_key(\n    dataset: str, revision: str, config: str, split: str, row_idx: int, column: str, filename: str\n) -> str:\n    return f\"{parse.quote(dataset)}/{DATASET_SEPARATOR}/{revision}/{DATASET_SEPARATOR}/{parse.quote(config)}/{parse.quote(split)}/{str(row_idx)}/{parse.quote(column)}/{filename}\"\n\n\ndef create_image_file(\n    dataset: str,\n    revision: str,\n    config: str,\n    split: str,\n    row_idx: int,\n    column: str,\n    filename: str,\n    image: Image.Image,\n    format: str,\n    storage_client: StorageClient,\n) -> ImageSource:\n    object_key = generate_object_key(\n        dataset=dataset,\n        revision=revision,\n        config=config,\n        split=split,\n        row_idx=row_idx,\n        column=column,\n        filename=filename,\n    )\n    if storage_client.overwrite or not storage_client.exists(object_key):\n        image = ImageOps.exif_transpose(image)  # type: ignore[assignment]\n        buffer = BytesIO()\n        image.save(fp=buffer, format=format)\n        buffer.seek(0)\n        with storage_client._fs.open(storage_client.get_full_path(object_key), \"wb\") as f:\n            f.write(buffer.read())\n    return ImageSource(src=storage_client.get_url(object_key), height=image.height, width=image.width)\n\n\ndef create_audio_file(\n    dataset: str,\n    revision: str,\n    config: str,\n    split: str,\n    row_idx: int,\n    column: str,\n    audio_file_bytes: bytes,\n    audio_file_extension: Optional[str],\n    filename: str,\n    storage_client: StorageClient,\n) -> list[AudioSource]:\n    object_key = generate_object_key(\n        dataset=dataset,\n        revision=revision,\n        config=config,\n        split=split,\n        row_idx=row_idx,\n        column=column,\n        filename=filename,\n    )\n    suffix = f\".{filename.split('.')[-1]}\"\n    if suffix not in SUPPORTED_AUDIO_EXTENSION_TO_MEDIA_TYPE:\n        raise ValueError(\n            f\"Audio format {suffix} is not supported. Supported formats are\"\n            f\" {','.join(SUPPORTED_AUDIO_EXTENSION_TO_MEDIA_TYPE)}.\"\n        )\n    media_type = SUPPORTED_AUDIO_EXTENSION_TO_MEDIA_TYPE[suffix]\n\n    if storage_client.overwrite or not storage_client.exists(object_key):\n        audio_path = storage_client.get_full_path(object_key)\n        if audio_file_extension == suffix:\n            with storage_client._fs.open(audio_path, \"wb\") as f:\n                f.write(audio_file_bytes)\n        else:  # we need to convert\n            # might spawn a process to convert the audio file using ffmpeg\n            with NamedTemporaryFile(\"wb\", suffix=audio_file_extension) as tmpfile:\n                tmpfile.write(audio_file_bytes)\n                segment: AudioSegment = AudioSegment.from_file(tmpfile.name)\n                buffer = BytesIO()\n                segment.export(buffer, format=suffix[1:])\n                buffer.seek(0)\n                with storage_client._fs.open(audio_path, \"wb\") as f:\n                    f.write(buffer.read())\n    return [AudioSource(src=storage_client.get_url(object_key), type=media_type)]\n", "path": "libs/libcommon/src/libcommon/viewer_utils/asset.py"}]}