MusicalInstrument - Play musical instrument in just few lines of swift code

Overview

MusicalInstrument

Swift

Play musical instrument in just few lines of swift code.

Requirements

  • Swift 5.0+
  • iOS 14.0+
  • macOS 13.0+

Install

Swift Package Manager

let package = Package(
  dependencies: [
    .package(url: "https://github.com/musical77/MusicalInstrument.git")
  ],
)

Usage

MusicalInstrument supports Piano and Violin right now.

Get a Piano and play with it!

You can hear the center C of the piano playing from the speakers.

// create a piano, and play middle C for a second.
let piano = Piano.default
piano.play(at: "C4", with: .intensity(60))
Thread.sleep(forTimeInterval: 1.0)
piano.stop(at: "C4")

Get a Violin and a Piano and play with it!

In this example, you can hear the sound, also get a recorded audio file.

// prepare piano and violin and audio recorder
let piano = Piano.default
let violin = Violin.default
let recorder = AudioRecorder(audioEngine: .default)

// start recording, save audio file (*.caf) to your faviorate destination.
_ = recorder.startRecording(saveTo: URL(...))

// let's play some music
violin.play(at: "E4", with: .intensity(100))
piano.play(at: "C4", with: .intensity(50))
piano.play(at: "E4", with: .intensity(50))
piano.play(at: "G4", with: .intensity(50))
Thread.sleep(forTimeInterval: 1.0)
violin.stop(at: "E4")
piano.stopAll()

violin.play(at: "D4", with: .intensity(50))
piano.play(at: "B3", with: .intensity(50))
piano.play(at: "D4", with: .intensity(50))
piano.play(at: "G4", with: .intensity(50))
Thread.sleep(forTimeInterval: 1.0)
violin.stop(at: "D4")
piano.stopAll()

// stop recording and get audio file
let url = recorder.stopRecording()
print(url)

Recorded Audio Example

https://github.com/musical77/MusicalInstrument/blob/main/Examples/audio/pianoAndViolin.caf?raw=true

You might also like...
SPlayer - play mp3/pm4

SPlayer - play mp3/pm4

Soundable allows you to play sounds, single and in sequence, in a very easy way

Overview Soundable is a tiny library that uses AVFoundation to manage the playing of sounds in iOS applications in a simple and easy way. You can play

Play and share sound inserts from Medo e Delírio em Brasília, a Brazilian podcast.
Play and share sound inserts from Medo e Delírio em Brasília, a Brazilian podcast.

Play and share sound inserts from Medo e Delírio em Brasília, a Brazilian podcast.

Learn to Code While Building Apps - The Complete iOS Development Bootcamp
Learn to Code While Building Apps - The Complete iOS Development Bootcamp

Xylophone Our Goal The goal of this tutorial is to dive into a simple iOS recipe - how to play sound and use an Apple library called AVFoundation. The

Contains common infrastructural code for apps to communicate among computers, sound synthesizers, and other multimedia devices via OSC.

The CoreOSC package contains common infrastructural code for your apps to communicate among computers, sound synthesizers, and other multimedia devices via OSC.

Swift-music - swift-music is a swift package that provides an easy-to-use API for music related developments.

🎼 swift-music Introduction swift-music is a swift package that provides an easy-to-use API for music related developments. Currently available module

Beethoven is an audio processing Swift library
Beethoven is an audio processing Swift library

Beethoven is an audio processing Swift library that provides an easy-to-use interface to solve an age-old problem of pitch detection of musical signals.

MusicKit is a framework and DSL for creating, analyzing, and transforming music in Swift.

MusicKit MusicKit is a framework and DSL for creating, analyzing, and transforming music in Swift. Examples Functional harmony let C5 = Pitch(midi: 72

SwiftAudioPlayer - Swift-based audio player with AVAudioEngine as its base

SwiftAudioPlayer Swift-based audio player with AVAudioEngine as its base. Allows for: streaming online audio, playing local file, changing audio speed

Owner
null
A minimal AUv3 instrument example using AudioKit 5

AUv3 Instrument (AudioKit 5) A minimal AUv3 instrument example using AudioKit 5. Download the project, customize it however you like, and share your w

Nick Culbertson 24 Jan 4, 2023
Project by Group 6 - Good Morning | An assortment of musical theory tools

MusicalRooms Ever find yourself staring at theory books, unsure of when the obscure music terms will ever become second nature? Are you on your way to

Swift Innovators Network 7 Nov 4, 2022
Provides API access to localized musical instruments and their tunings.

instruments.fyi instruments.fyi provides API access to localized musical instruments and their tunings provided by InstrumentKit. Table of Contents Wo

Brian Drelling 10 Sep 5, 2022
Provides type-safe access to localized musical instruments and their tunings.

InstrumentKit InstrumentKit provides type-safe access to localized musical instruments and their tunings. Table of Contents Work In Progress Installat

Brian Drelling 14 Nov 3, 2022
The easiest way to prepare, play, and remove sounds in your Swift app!

Chirp The easiest way to prepare, play, and remove sounds in your Swift app! ##Installation ###CocoaPods Installation Chirp is available on CocoaPods.

null 309 Dec 17, 2022
KeyAudioManager - A swift package to make it a lot easier to play audio in your app

KeyAudioManager A swift package to make it a lot easier to play audio in your ap

Pedro Esli 3 Apr 28, 2022
AIB indicates for your app users which audio is playing. Just like the Podcasts app.

Audio Indicator Bars for iOS and tvOS Indicates for your app users which audio is playing. Just like the Podcasts app. Index Requirements and Details

Leonardo Cardoso 285 Nov 23, 2022
SoundManager - A simple framework to load and play sounds in your app.

SoundManager - A simple framework to load and play sounds in your app.

Jonathan Chacón 3 Jan 5, 2022
Subsonic is a small library that makes it easier to play audio with SwiftUI

Subsonic is a small library that makes it easier to play audio with SwiftUI

Paul Hudson 218 Dec 16, 2022
An iOS app that visually clones Spotify's app and consumes the official Spotify's Web API to show(and play) songs, podcasts, artists and more.

SpotifyClone An iOS app that visually clones Spotify's app and consumes the official Spotify's Web API to show(and play) songs, podcasts, artists and

null 104 Jan 7, 2023