Skip to content

Issue passing bytes as stream to recognize song #61

Answered by MoppyDev
captain-cronch asked this question in Q&A
Discussion options

You must be logged in to vote

Without AudioSegment you just need to getvalue on the bytes:

import asyncio
from shazamio import Shazam
import json
import soundfile as sf
import sounddevice as sd
from io import BytesIO

RATE = 44100
CHUNK = 1024
SECONDS = 10

print("recording...")
data = sd.rec(int(SECONDS * RATE), samplerate=RATE, channels=1)
sd.wait()

file_format = "WAV"
memory_file = BytesIO( )
sf.write( memory_file, data, RATE, format = file_format )

memory_file.seek( 0 )

async def main(memory_file):
  shazam = Shazam()
  out = await shazam.recognize_song(memory_file.getvalue())
  print(json.dumps(out, indent=10))

response = asyncio.run(main(memory_file))

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@captain-cronch
Comment options

Comment options

You must be logged in to vote
1 reply
@MoppyDev
Comment options

Answer selected by dotX12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants