Traceback (most recent call last): File…
- User
Traceback (most recent call last): File "C:\Users\ILEG-i5-11\Downloads\Compressed\MyProj\ShazamIdentify.py", line 5, in shazam = Shazam( ^^^^^^^ TypeError: Shazam.init() got an unexpected keyword argument 'lang'
from ShazamAPI import Shazam
mp3_file_content_to_recognize = open('Unknown_file - Copy.mp3', 'rb').read()
shazam = Shazam( mp3_file_content_to_recognize, lang='en', time_zone='Europe/Paris' ) recognize_generator = shazam.recognizeSong() while True: print(next(recognize_generator)) # current offset & shazam response to recognize requests
- Assistant
The error message you received is indicating that the
Shazamclass's__init__method does not accept alangkeyword argument, which you're attempting to pass. This error can occur if the version of theShazamAPIyou're using does not support these arguments or if you're passing parameters incorrectly based on the library's usage documentation. - User
Traceback (most recent call last): File "C:\Users\ILEG-i5-11\Downloads\Compressed\MyProj\ShazamIdentify.py", line 35, in mp3_file_content_to_recognize.close() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'bytes' object has no attribute 'close'
- Assistant
The error you're seeing,
AttributeError: 'bytes' object has no attribute 'close', is occurring because you're attempting to close the bytes objectmp3_file_content_to_recognizeas if it were a file. In your script,mp3_file_content_to_recognizeis actually the contents of a file read into memory as bytes, not the file object itself. To fix this issue, you should properly manage the file object used to read the MP3 contents.Here's how you can adjust your script to correctly handle the file:
from ShazamAPI import Shazam # Use a with statement to ensure the file is properly opened and closed with open('Unknown_file - Copy.mp3', 'rb') as file: mp3_file_content_to_recognize = file.read() # Initialize the Shazam object without the 'lang' and 'time_zone' arguments shazam = Shazam(mp3_file_content_to_recognize) recognize_generator = shazam.recognizeSong() try: while True: # Print current offset & Shazam response to recognize requests print(next(recognize_generator)) except StopIteration: # This exception will be raised when the generator has no more items print("Finished recognizing the song.") - User
- Assistant
- User
Traceback (most recent call last): File "D:\Eurydice\Encompassing Data by discerning\Eury1.py", line 13, in from ShazamAPI import shazam_recognize_song ImportError: cannot import name 'shazam_recognize_song' from 'ShazamAPI' (D:\myenv\Lib\site-packages\ShazamAPI_init_.py)
from ShazamAPI import Shazam
Use a with statement to ensure the file is properly opened and closed
with open('Unknown_file - Copy.mp3', 'rb') as file: mp3_file_content_to_recognize = file.read()
Initialize the Shazam object without the 'lang' and 'time_zone' arguments
shazam = Shazam(mp3_file_content_to_recognize) recognize_generator = shazam.recognizeSong()
try: while True: # Print current offset & Shazam response to recognize requests print(next(recognize_generator))
except StopIteration: # This exception will be raised when the generator has no more items print("Finished recognizing the song.") - Assistant
- User
def get_user_choice(): print(“Select the recognition service to use:”) print(“1: ACRCloud”) print(“2: Shazam”) choice = input("Enter your choice (1 or 2): ") return choice
do thsi more decoration
- Assistant
If you're aiming to make your user interface (UI) more engaging or visually appealing, especially in a console-based application, you might consider adding simple decorative elements, instructions, or even clear separation lines. It's important to keep the UI user-friendly and not to overdo it with too many decorative elements which could lead to clutter. Below is a revised
get_user_choicefunction with some added flair:def get_user_choice(): # Display a header print("=" * 50) print("Welcome to the Song Recognition Service!") print("=" * 50) # Provide instructions and options print("\nPlease select the recognition service you'd like to use:\n") print(" 1: ACRCloud - Fast and accurate music recognition") print(" 2: Shazam - Discover music, artists, and lyrics in seconds") # Separator for aesthetic purposes print("-" * 50) # Input prompt choice = input("Enter your choice (1 or 2) and press Enter: ") # More flair to indicate processing/input received print("\n" + "." * 25 + " Processing " + "." * 25 + "\n") return choice - User
- Assistant
- User
create configuration file like config.json for ACR_HOST ACR_ACCESS_KEY ACR_ACCESS_SECRET
- Assistant
To create a configuration file for sensitive data, such as API keys and secrets, using JSON format is a common and convenient approach. Here’s how you can do it:
- Create the
config.jsonFile:
First, create a
config.jsonfile in a secure location within your project directory (or wherever you deem it to be safest). Make sure this file is listed in your or equivalent to prevent it from being uploaded to version control if you are using one. - Create the
- User
recognize init(none access_key or access_secret)
- Assistant
- User
- Assistant