How to play base64-encoded sound in Python [duplicate]

I want to play a base64-encoded sound in Python, I've tried using Pygame.mixer but all I get is a hiss of white noise.

This is an example of my code:

import pygame

coinflip = b'data:audio/ogg;base64,T2dnUwACAAAAAAAAAACYZ...'  # Truncated for brevity
flip  = pygame.mixer.Sound(coinflip)
ch = flip.play()
while ch.get_busy():
    pygame.time.wait(100)

The pygame mixer works well if I import a wav/mp3/ogg file, but I want to write a compact self-contained program that doesn't need external files, so I'm trying to embed a base64 encoded version of the sound in the Python code.

NB: The solution doesn't need to be using pygame, but it would be preferable since I'm already using it elsewhere in the program.



Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation