@JonB, i appreciate your help. Thank you. I need some time to process your answer but now I think everything will be fine.
Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Latest posts made by geniu
-
RE: Voice recorder and play sound
-
RE: Voice recorder and play sound
Here is my new code.
import ui from sound import Recorder from sound import Player class recorderView(ui.View): def __init__(self): self.file = '4.m4a' self.player = Player(self.file) self.recorder = Recorder(self.file) record_button = ui.ButtonItem() record_button.title = 'record' record_button.action = self.rec play_button = ui.ButtonItem() play_button.title = 'play' play_button.tint_color = 'red' play_button.action = self.play self.right_button_items = [record_button, play_button] def rec(self, sender): self.recorder.record(3) print(self.recorder.recording) def play(self, sender): print('before calling play method:', self.player.playing) self.player.play() print('after calling play method:', self.player.playing) v = recorderView() v.name = 'Recorder' v.present('sheet')
And here is the piece of play method’s code:
print('before calling play method:', self.player.playing) self.player.play() print('after calling play method:', self.player.playing)
After launch app if I firstly tap the play button sound is playing and output is:
before calling play method: False
after calling play method: TrueBut after recording sound is not playing although
player
exists.
Because I can get player’s attributes.
The output is:before calling play method: False
after calling play method: False -
RE: Voice recorder and play sound
@cvp this doesn't work. Play still plays after reload app.
@JonB, could you give an example how can I make a custom class? -
RE: Voice recorder and play sound
@cvp said:
@geniu something like
import sound from sound import Player import ui def play(sender): sender.player.play() v_str = ''' [ { "nodes" : [ { "nodes" : [ ], "frame" : "{{80, 104}, {80, 32}}", "class" : "Button", "attributes" : { "action" : "play", "frame" : "{{80, 104}, {80, 32}}", "title" : "Play", "uuid" : "1D1987D9-DAFA-4228-A0D4-CCDBE54B962B", "class" : "Button", "name" : "play_button", "font_size" : 15, "border_width" : 1 }, "selected" : true } ], "frame" : "{{0, 0}, {240, 240}}", "class" : "View", "attributes" : { "enabled" : true, "background_color" : "RGBA(1.000000,1.000000,1.000000,1.000000)", "tint_color" : "RGBA(0.000000,0.478000,1.000000,1.000000)", "border_color" : "RGBA(0.000000,0.000000,0.000000,1.000000)", "flex" : "" }, "selected" : false } ] ''' v = ui.load_view_str(v_str) v['play_button'].player = Player('4.m4a') v.present('sheet')
Thank you. I'll try and let you know if this works.
-
RE: Voice recorder and play sound
@cvp said:
@geniu said:
It plays nothing
Sure that your file exists and is not empty? Try it by tapping on it in the Pythonista files browser, then Quick Look, then the play button
Yes, I am. I can play it by Quick Look.
Andprint(os.listdir())
inside the play function shows that the file exists. And I can play it from console by creation a new Player instance -
RE: Voice recorder and play sound
@JonB said:
@geniu Player(filename) loads the file when the Player is created. So it should be clear that, since your file has not yet been recorded, the player is loading the old file.
a better approach would be to set the play button disabled initially, and during the record function. then, enable it in stop_record. instantiate the Player as a local variable within the play button action, so it always reloads the file.
I am not sure we have the ability to easily control which speake is used, except by using an objc approach.
Thank you for explaining. Now it clear for me. I've tried to create Player in a play function firstly, but it doesn't seem to work. It plays nothing
-
RE: Voice recorder and play sound
@mikael said:
@geniu, I might be mistaken, but your code does not seem to do anything, as none of the functions get called.
Regarding the external/device speaker, that is something I would change from device settings. Can you please explain a bit more?
Sorry I didn't explain it. As @cvp mentioned functions are called by buttons. I have 3 buttons: record, stop record and play.
Could you explain where is these settings? I cannot find it.
-
Voice recorder and play sound
Hi!
I am trying write a simple recorder.
After recording the Player.play doesn’t play file. It works only after reload app
And secondly it plays from the inner speaker.
How can I fix it?
How can i change audio output from inner speaker to speaker phone and play recorded sound consistently after recording ?Here is my code:
import sound from sound import Recorder from sound import Player sound.set_volume(1) recorder = Recorder('4.m4a') player = Player('4.m4a') def record(sender): global recorder recorder.record() def stop_record(sender): global recorder recorder.stop() def play(sender): global player player.play() v = ui.load_view() v.present('sheet')