LoginSignup
30
30

More than 5 years have passed since last update.

まるでHHKBのような打鍵音を演出するzen-typing

Last updated at Posted at 2015-08-26

こんにちは。
まるでHHKBのように軽快な打鍵音を演出するzen-typingというものを作ったのでご紹介します。

つかいかた

  1. できるだけ高級なイヤフォンを用意します。
  2. Macにイヤフォンを接続します。
  3. 上のリポジトリをクローンしましょう。
  4. ZenTyping.playgroundをXcodeで開きます。
  5. 数秒待ったら、タイピングしてましょう。
  6. カチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャカチャ

  7. ッターーーーーーーーーーーーーン

いやーーーーーーーー気持ちいい!!!!!

カスタマイズしよう

実はこのプログラム、とても短いので自分でも簡単に作ることができます。

まず、Xcodeでplaygroundを作ります。

スクリーンショット 2015-08-26 20.16.10.png

ポイントは、platformをOSXにすることです。こうしないとうまく動いてくれません。

スクリーンショット 2015-08-26 20.16.40.png

プレイグラウンドを開いたら、下のコードを貼り付けます。
たったこれだけでOK。数秒待つと動作します。

//: Playground - noun: a place where people can play

import AVFoundation

var engine = AVAudioEngine()
var input = engine.inputNode
var output = engine.outputNode
var format = input.inputFormatForBus(0)
var error:NSError?

engine.connect(input, to: output, format: format)

while true {
    engine.startAndReturnError(&error)
    sleep(10000)
}

スクリーンショット 2015-08-26 20.17.28.png

このプログラム、簡単にサウンドエフェクトなどを追加できます。
たとえば、下のコードを貼り付けると、まるで銭湯でタイピングしているような感覚になります。

//: Playground - noun: a place where people can play

import AVFoundation

var engine = AVAudioEngine()
var input = engine.inputNode
var output = engine.outputNode
var format = input.inputFormatForBus(0)
var error:NSError?

var reverb = AVAudioUnitReverb()
reverb.loadFactoryPreset(.LargeHall2)
reverb.wetDryMix = 50
engine.attachNode(reverb)

engine.connect(input, to: reverb, format: format)
engine.connect(reverb, to: output, format: format)

while true {
    engine.startAndReturnError(&error)
    sleep(10000)
}

.LargeHall2を別の部屋に変えてみたり、wetDryMixの値を変えてみるといろいろとカスタマイズできます。
AVAudioUnitReverb以外にも、AVAudioUnitDelayなどいろいろ使えます。

みなさんのとっておきの打鍵音を作ったら、ぜひぜひ上のリポジトリにプルリクエストを送ってくださいね。

それでは。enjoy coding!

30
30
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
30
30