flutter_acrcloud 0.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • new56

flutter_acrcloud #

A Flutter plugin for the ACRCloud music recognition API. This is a third-party plugin; there is no relation between the developer and ACRCloud.

Note: I built this plugin to support a personal project. As such, it is very bare bones and potentially buggy. If you encounter a bug or need a feature added, you can open an issue or, better yet, fix it yourself and submit a PR.

Setup #

In order to get access to the microphone, you have to explicitly list the required permission in your iOS and Android apps.

iOS #

  1. Open ios/Runner/Info.plist.

  2. Add the following lines somewhere inside of the <dict>:

    <key>NSMicrophoneUsageDescription</key>
    <string>Recognize the music around you</string>
    
  3. You can replace the <string> with whatever message you want. This message will be displayed in the alert that asks the user to grant permission to access to the microphone.

Android #

  1. Open android/app/src/main/AndroidManifest.xml

  2. Add the following line inside of the <manifest> and above the <application>:

    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    

Usage #

Consult the example app for a real-world example.

  1. Call ACRCloud.setUp() to provide your API key, API secret, and preferred host. setUp() takes an instance of ACRCloudConfig.
  2. When you want to recognize a song, call ACRCloud.startSession() to start a recording session. You will get an instance of ACRCloudSession that you can use to interact with the session.
  3. To get the current volume, you can use the volume property of ACRCloudSession. This is a Stream that is updated every time a new volume value is recoded.
  4. To cancel a session, just call cancel() on the session.
  5. To get the result of a session, you can await the result property of the session. If the result is null, then the request was cancelled. Otherwise, you'll get an instance of ACRCloudResponse that contains all the information.

0.0.1 #

  • Initial release!

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_acrcloud/acrcloud_response.dart';
import 'package:flutter_acrcloud/flutter_acrcloud.dart';
import 'package:flutter_acrcloud_example/env.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  ACRCloudResponseMusicItem music;

  @override
  void initState() {
    super.initState();
    ACRCloud.setUp(ACRCloudConfig(apiKey, apiSecret, host));
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Flutter_ACRCloud example app'),
        ),
        body: Center(
          child: Column(
            children: [
              Builder(
                  builder: (context) => RaisedButton(
                      onPressed: () async {
                        setState(() {
                          music = null;
                        });

                        final session = ACRCloud.startSession();

                        showDialog(
                            context: context,
                            barrierDismissible: false,
                            builder: (context) => AlertDialog(
                                  title: Text('Listening...'),
                                  content: StreamBuilder(
                                    stream: session.volume,
                                    initialData: 0,
                                    builder: (context, snapshot) =>
                                        Text(snapshot.data.toString()),
                                  ),
                                  actions: [
                                    FlatButton(
                                      child: Text('Cancel'),
                                      onPressed: session.cancel,
                                    )
                                  ],
                                ));

                        final result = await session.result;
                        Navigator.pop(context);

                        setState(() {
                          if (result == null) {
                            // Cancelled
                            return;
                          } else if (result.metadata == null) {
                            Scaffold.of(context).showSnackBar(SnackBar(
                              content: Text('No result'),
                            ));
                            return;
                          }

                          music = result.metadata.music.first;
                        });
                      },
                      child: Text('Listen'))),
              if (music != null) Text('Track: ${music.title}\n'),
              if (music != null) Text('Album: ${music.album.name}\n'),
              if (music != null) Text('Artist: ${music.artists.first.name}\n'),
            ],
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_acrcloud: ^0.0.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_acrcloud/flutter_acrcloud.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
19
Health:
Code health derived from static analysis. [more]
97
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
86
Overall:
Weighted score of the above. [more]
56
Learn more about scoring.

We analyzed this package on Jul 2, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because of import path [package:flutter_acrcloud/flutter_acrcloud.dart] that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because of import path [package:flutter_acrcloud/flutter_acrcloud.dart] that declares support for platforms: android, ios

Package does not support Flutter platform web

Because of import path [package:flutter_acrcloud/flutter_acrcloud.dart] that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because of import path [package:flutter_acrcloud/flutter_acrcloud.dart] that declares support for platforms: android, ios

Package not compatible with SDK dart

because of import path [flutter_acrcloud] that is in a package requiring null.

Health suggestions

Fix lib/acrcloud_response.g.dart. (-2.96 points)

Analysis of lib/acrcloud_response.g.dart reported 6 hints, including:

line 22 col 22: The declaration '_$ACRCloudResponseToJson' isn't referenced.

line 37 col 22: The declaration '_$ACRCloudResponseStatusToJson' isn't referenced.

line 56 col 22: The declaration '_$ACRCloudResponseMetadataToJson' isn't referenced.

line 84 col 22: The declaration '_$ACRCloudResponseMusicItemToJson' isn't referenced.

line 106 col 22: The declaration '_$ACRCloudResponseAlbumToJson' isn't referenced.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

The package description is too short. (-4 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
json_annotation ^3.0.1 3.0.1
rxdart ^0.24.1 0.24.1
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
build_runner ^1.10.0
flutter_test
json_serializable ^3.3.0