📜 ⬆️ ⬇️

Active noise reduction of the shutter sound in the camera of the mobile device

Cameras of mobile devices Android / iOS / etc. when taking pictures, they produce a characteristic shutter sound. In some countries this is required by law. But what to do if our program still needs to take a picture silently, even if it is not visible to the user? There is such a way.



Habrahabr user k06a (Anton Bukov) on Stackoverflow offered a universal way that should work on all platforms. He suggests using active noise cancellation, that is, invert the sound and run the inverted copy immediately before the original one. We get absolutely silent photography!

k06a explains with iOS as an example.
')
1. Record the system shutter sound. The ways in which sounds lie in the file system can be viewed in the iOSSystemSoundsLibrary code.

NSString *path = @"/System/Library/Audio/UISounds/photoShutter.caf"; NSString *docs = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; NSData *data = [NSData dataWithContentsOfFile:path]; [data writeToFile:[docs stringByAppendingPathComponent:@"photoShutter.caf"] atomically:YES]; 

2. photoShutter.caf file from the Documents folder, you can use DiskAid for Mac.

3. Open the photoShutter.caf in the audio editor (Audacity) and apply investment.

4. Save the resulting sound in iOS and launch it directly in front of the captureStillImageAsynchronouslyFromConnection .

 static SystemSoundID soundID = 0; if (soundID == 0) { NSString *path = [[NSBundle mainBundle] pathForResource:@"photoShutter2" ofType:@"caf"]; NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO]; AudioServicesCreateSystemSoundID((__bridge CFURLRef)filePath, &soundID); } AudioServicesPlaySystemSound(soundID); [self.stillImageOutput captureStillImageAsynchronouslyFromConnection: ... 

Anton says that works fine.

If anything, then already inverted photoShutter2.caf can be taken here ( mirror ).

Source: https://habr.com/ru/post/224055/


All Articles