from pydub import AudioSegment
from io import BytesIO


def convert_to_ogg(f):
    bio = BytesIO()

    AudioSegment.from_file(f).export(bio, format='ogg')
    bio.seek(0)

    return bio

from pydub import AudioSegment
from io import BytesIO


def convert_to_ogg(f):
    bio = BytesIO()

    AudioSegment.from_file(f).export(bio, format='ogg', codec='libopus')
    bio.seek(0)

    return bio

Use libopus codec while converting to Voice
Use libopus codec while converting to Voice

  from pydub import AudioSegment
  from io import BytesIO
  
  
  def convert_to_ogg(f):
      bio = BytesIO()
  
-     AudioSegment.from_file(f).export(bio, format='ogg')
+     AudioSegment.from_file(f).export(bio, format='ogg', codec='libopus')
      bio.seek(0)
  
      return bio
  
Use libopus codec while converting to Voice
## Code Before:
from pydub import AudioSegment
from io import BytesIO


def convert_to_ogg(f):
    bio = BytesIO()

    AudioSegment.from_file(f).export(bio, format='ogg')
    bio.seek(0)

    return bio

## Instruction:
Use libopus codec while converting to Voice
## Code After:
from pydub import AudioSegment
from io import BytesIO


def convert_to_ogg(f):
    bio = BytesIO()

    AudioSegment.from_file(f).export(bio, format='ogg', codec='libopus')
    bio.seek(0)

    return bio
