Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio recording for macOS #428

Merged
merged 11 commits into from
Oct 12, 2018
Merged

Audio recording for macOS #428

merged 11 commits into from
Oct 12, 2018

Conversation

Nephyx
Copy link
Contributor

@Nephyx Nephyx commented Oct 6, 2018

Added audio recording and playback for macOS using Apple's Objective-C API via pyobjus.
Audio files are recorded with 44.1 kHz sample rate in WAV format.

Closes issue #282.


class OSXAudio(Audio):
def __init__(self, file_path=None):
default_path = join(expanduser('~'), 'Desktop', 'audio.wav')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not pass a default value that point on nothing :) Should be None by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried without passing a value of None, but I started getting the following error:
`>>> from plyer import audio

audio.start()
Traceback (most recent call last):
File "/Users/maroskovac/Dev/plyer/plyer/utils.py", line 96, in _ensure_obj
obj = mod.instance()
File "/Users/maroskovac/Dev/plyer/plyer/platforms/macosx/audio.py", line 82, in instance
return OSXAudio()
TypeError: init() takes exactly 2 arguments (1 given)
Traceback (most recent call last):
File "", line 1, in
File "/Users/maroskovac/Dev/plyer/plyer/facades/audio.py", line 65, in start
self._start()
File "/Users/maroskovac/Dev/plyer/plyer/facades/audio.py", line 98, in _start
raise NotImplementedError()
NotImplementedError`

# of the last recorded audio file
self._player = AVAudioPlayer.alloc()
self._player = self._player.initWithContentsOfURL_error_(
self._current_file, None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to catch the error and raise an exception if something failed, rather than completely ignore.

@tito tito self-assigned this Oct 6, 2018
@Nephyx
Copy link
Contributor Author

Nephyx commented Oct 7, 2018

@tito here's a quick summary of my commits addressing your changes request:

  • removed all prints
  • kept passing file_path with default value of None, as removing it as per your suggestion causes NotImplementedError (more in my reply to your change request)
  • added raising exceptions in case of recorder or player initialization errors (using only one NSError instance because of segmentation faults in case of multiple NSError allocs and actually, there's no need to have more than one instance)

@Nephyx Nephyx changed the title Audio recording for iOS and macOS Audio recording for macOS Oct 12, 2018
@tito tito merged commit b558664 into kivy:master Oct 12, 2018
@tito
Copy link
Member

tito commented Oct 12, 2018

Thanks you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants