Search Results

Search found 4 results on 1 pages for 'aaronstacy'.

Page 1/1 | 1 

  • record output sound in python

    - by aaronstacy
    i want to programatically record sound coming out of my laptop in python. i found PyAudio and came up with the following program that accomplishes the task: import pyaudio, wave, sys chunk = 1024 FORMAT = pyaudio.paInt16 CHANNELS = 1 RATE = 44100 RECORD_SECONDS = 5 WAVE_OUTPUT_FILENAME = sys.argv[1] p = pyaudio.PyAudio() channel_map = (0, 1) stream_info = pyaudio.PaMacCoreStreamInfo( flags = pyaudio.PaMacCoreStreamInfo.paMacCorePlayNice, channel_map = channel_map) stream = p.open(format = FORMAT, rate = RATE, input = True, input_host_api_specific_stream_info = stream_info, channels = CHANNELS) all = [] for i in range(0, RATE / chunk * RECORD_SECONDS): data = stream.read(chunk) all.append(data) stream.close() p.terminate() data = ''.join(all) wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb') wf.setnchannels(CHANNELS) wf.setsampwidth(p.get_sample_size(FORMAT)) wf.setframerate(RATE) wf.writeframes(data) wf.close() the problem is i have to connect the headphone jack to the microphone jack. i tried replacing these lines: input = True, input_host_api_specific_stream_info = stream_info, with these: output = True, output_host_api_specific_stream_info = stream_info, but then i get this error: Traceback (most recent call last): File "./test.py", line 25, in data = stream.read(chunk) File "/Library/Python/2.5/site-packages/pyaudio.py", line 562, in read paCanNotReadFromAnOutputOnlyStream) IOError: [Errno Not input stream] -9975 is there a way to instantiate the PyAudio stream so that it inputs from the computer's output and i don't have to connect the headphone jack to the microphone? is there a better way to go about this? i'd prefer to stick w/ a python app and avoid cocoa.

    Read the article

  • convert string to argv in c++

    - by aaronstacy
    I have an std::string containing a command to be executed with execv, what is the best "C++" way to convert it to the "char *argv[]" that is required by the second parameter of execv()? To clarify: std::string cmd = "mycommand arg1 arg2"; char *cmd_argv[]; StrToArgv(cmd, cmd_argv); // how do I write this function? execv(cmd_argv[0], cmd_argv);

    Read the article

  • writing a meta refresh method for rails

    - by aaronstacy
    I want a method in app/controllers/application.rb that can prepend/append text to whatever template gets rendered. Of course I can't call render twice w/o getting a double render error, so is this possible? I want to redirect after a delay using a meta refresh. Here's what I've got: app/controllers/application_controller.rb: def redirect_after_delay (url, delay) @redirect_delay = delay @redirect_url = url render end app/views/layouts/application.html.erb <!DOCTYPE html> <html lang="en"> <head> <%= yield :refresh_tag %> </head> <body> <%= yield %> </body> </html> So then if I want to add a redirect-after-delay, I add the following to 1) my controller and 2) the action's view: app/controllers/my_controller.rb def my_action redirect_after_delay 'http://www.google.com', 3 if some_condition end app/views/my_controller/my_action.html.erb <% content_for :refresh_tag do %> <meta http-equiv='refresh' content='<%=@redirect_delay%>;url=<%=@redirect_url%>'> <% end %> <h1>Please wait while you are redirected...</h1> Since the content_for block never changes, is it possible to do this in some generic way so that I don't have to put <%= yield :refresh_tag %> in each template? (e.g. could redirect_after_delay add it into whatever template is going to be rendered?)

    Read the article

  • Delegates vs. events in Cocoa

    - by aaronstacy
    I'm writing my first iPhone app, and I've been exploring the design patterns in Cocoa and Objective-C. I come from a background of client-side web development, so I'm trying to wrap my head around delegates. Specifically, I don't see why delegate objects are needed instead of event handlers. For instance, when the user presses a button, it is handled with an event (UITouchUpInside), but when the user finishes inputting to a text box and closes it with the 'Done' button, the action is handled by calling a method on the text box's delegate (textFieldShouldReturn). Why use a delegate method instead of an event? I also notice this in the view controller with the viewDidLoad method. Why not just use events?

    Read the article

1