code: def get_text_query_with_resource_limit_checks(
      client, query: str, filters: list, fields: str, page_size: int
  ):
      """
      Performs a text query, checks for rate / api limits, and retries.
  
      Args:
          client: FreesoundAPI client
          query: query string (either exact or inexact)
          filters: list of string filters
          fields: String of values to recover
          page_size: samples per page returned
  
      Returns:
  
      """
      pages = None
      attempts = 20
  
      while pages is None:
          try:
              pages = client.text_search(
                  query=query,
                  filter=" ".join(filters),
                  fields=fields,
                  page_size=str(page_size),
              )
  
          except freesound.FreesoundException as e:
              # Most probably a rate limit or a request limit
              # Check if that was the case, and wait appropriate ammount of time
              # for retry
              was_resource_limited = is_resource_limited(e)
  
              # If result of test False, it means that failure was due to some other reason.
              # Log it, then break loop
              if not was_resource_limited:
                  print(e.with_traceback(None))
                  break
  
          attempts -= 1
  
          # Attempt to refresh tokens if it fails multiple times
          if attempts % 5 == 0 and attempts > 0:
              session = instantiate_session()
              refresh_token(session)
              session.close()
              token = unpickle_object("_token")
              client = prepare_client(client, token)
  
          if attempts <= 0:
              print(
                  f"Failed to query pages for '{query}' after 10 attempts, skipping query"
              )
              break
  
          if pages is None:
              print(f"Query attempts remaining = {attempts}")
  
      return client, pages
  
file_path: NeMo/scripts/freesound_download_resample/freesound_download.py
imports: import argparse
  import os
  import pickle
  import time
label_desc: Use image node_id 8 for calling a global function with example usage: get_text_query_with_resource_limit_checks(client, query, filters, fields, page_size) and returns: client,  pages