#!/usr/bin/python2.5 # # Copyright (C) 2008 Angus Ainslie. # Copyright (C) 2008 Rob Sims. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # import sys import dbus import alsaaudio import time import os bus = dbus.SystemBus(); btpwr_obj = bus.get_object('org.freesmartphone.odeviced', '/org/freesmartphone/Device/PowerControl/Bluetooth') btpwr_iface = dbus.Interface(btpwr_obj, 'org.freesmartphone.Device.PowerControl') if not btpwr_iface.GetPower(): print 'Turning on Bluetooth power' btpwr_iface.SetPower(1) if not btpwr_iface.GetPower(): raise "FunctionalError", "Bluetooth power is stuck off" bz_manager = dbus.Interface(bus.get_object('org.bluez', '/org/bluez'), 'org.bluez.Manager') audio_bus = bz_manager.ActivateService('audio') audio = dbus.Interface(bus.get_object(audio_bus, '/org/bluez/audio'), 'org.bluez.audio.Manager') try: headset_path = audio.DefaultHeadset(); except: print "Can't find default headset." headset_path = '/org/bluez/audio/device0' headset_dev = dbus.Interface(bus.get_object(audio_bus, headset_path), 'org.bluez.audio.Device') print "Using", headset_dev.GetName(), "-", headset_dev.GetAddress() headset_hs = dbus.Interface(bus.get_object(audio_bus, headset_path), 'org.bluez.audio.Headset') if not headset_hs.IsConnected(): # if headset_hs.IsPlaying(): # print 'Headset is playing audio. Stopping.' # headset_hs.Stop() # print 'Headset is connected. Disconnecting.' # headset_hs.Disconnect() # time.sleep(4) print 'Connecting Headset.' try: headset_hs.Connect() except: print 'Failed to connect to headset.' # exit(1) # Set up sound card # The setup of the hifi DAC (hw:0,0) shouldn't be necessary, but my setup # refuses to talk over the VX interface unless I do this. Anything that # stimulates the hifi interface seems to work, but this is short. device = "hw:0,0" hpcm_play = alsaaudio.PCM( alsaaudio.PCM_PLAYBACK, alsaaudio.PCM_NONBLOCK, device ) hpcm_cap = alsaaudio.PCM( alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NONBLOCK, device ) print 'Adjusting card:', hpcm_play.cardname() hpcm_play.setchannels(2) hpcm_play.setrate(44100) hpcm_play.setformat(alsaaudio.PCM_FORMAT_S16_LE) hpcm_play.setperiodsize(500) hpcm_cap.setchannels(2) hpcm_cap.setrate(44100) hpcm_cap.setformat(alsaaudio.PCM_FORMAT_S16_LE) hpcm_cap.setperiodsize(500) del(hpcm_play) del(hpcm_cap) device = "hw:0,1" pcm_play = alsaaudio.PCM( alsaaudio.PCM_PLAYBACK, alsaaudio.PCM_NONBLOCK, device ) pcm_cap = alsaaudio.PCM( alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NONBLOCK, device ) print 'Adjusting card:', pcm_play.cardname() pcm_play.setchannels(1) pcm_play.setrate(8000) pcm_play.setformat(alsaaudio.PCM_FORMAT_S16_LE) pcm_play.setperiodsize(500000) pcm_cap.setchannels(1) pcm_cap.setrate(8000) pcm_cap.setformat(alsaaudio.PCM_FORMAT_S16_LE) pcm_cap.setperiodsize(500000) #print 'Connecting Headset.' #try: # headset_hs.Connect() #except: # print 'Failed to connect to headset.' # exit(1) print 'Playing Headset.' headset_hs.Play() print "Waiting for call to end - hit ENTER" sys.stdin.read(1) headset_hs.Stop() #headset_hs.Disconnect()