Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call recognize on AudioSegment #103

Open
Andrew3019 opened this issue Apr 16, 2024 · 1 comment
Open

Call recognize on AudioSegment #103

Andrew3019 opened this issue Apr 16, 2024 · 1 comment
Labels
question Further information is requested

Comments

@Andrew3019
Copy link

Hello, it seems after the update from recognize_song to recognize, you can no longer pass an AudioSegment as an argument. Is there any workaround for this? I used AudioSegment to separate different tracks in an audio file with many different songs in it.

I have tried out = await shazam.recognize(segment.raw_data) which should be type "bytes" but this error occurs:
signature = await self.core_recognizer.recognize_bytes(data) SignatureError: FFmpeg not found or failed to convert audio

@dotX12
Copy link
Collaborator

dotX12 commented Apr 27, 2024

@pytest.mark.asyncio
async def test_recognize_audio_segment_cut_half(song_bytes: bytes):
    audio_data = BytesIO(song_bytes)
    audio_segment = AudioSegment.from_file(audio_data, format="ogg")
    half_duration = len(audio_segment) // 2
    half_audio = audio_segment[:half_duration]
    
    buffer = half_audio.export(format="wav")
    audio_bytes = buffer.read()

    shazam = Shazam()
    out = await shazam.recognize(data=audio_bytes)

    assert out.get("matches") != []
    assert out["track"]["key"] == "53982678"

@Andrew3019,

obj.raw_data doesn't work for me, but it works great

buffer = half_audio.export(format="wav")
audio_bytes = buffer.read()
============================================================================== test session starts ==============================================================================
platform win32 -- Python 3.11.4, pytest-8.1.2, pluggy-1.5.0
rootdir: C:\Users\ecelo\PycharmProjects\ShazamIO
configfile: pyproject.toml
plugins: anyio-4.3.0, asyncio-0.23.6
asyncio: mode=Mode.AUTO
collected 8 items                                                                                                                                                                

tests\test_21_issue.py .
tests\test_about_artist.py .
tests\test_get_next_signature.py ..
tests\test_peak_spreading_numpy.py .
tests\test_recognize.py ...

=============================================================================== 8 passed in 5.12s ===============================================================================

@dotX12 dotX12 added the question Further information is requested label Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants