0

I want to stream music from my laptop with Ubuntu 18.04 to audio device (LG CM2760). I wrote short script in Python where I want to connect with my audio device and then play music. I'm not sure but think that connection is established correct because LG shows my laptops' name. Unfortunately, when I start 'streaming' there is nothing but silence. Problem may be with bytes version of song but I've done 2 days research and found nothing which could help me to solve this.

I tried to convert song to other formats.

import bluetooth
from time import sleep

uuid_to_find = "110D"
service_matches = bluetooth.find_service(uuid=uuid_to_find)

first_match = service_matches[0]
port = first_match["port"]
host = first_match["host"]

print(port)
print(host)

sock = bluetooth.BluetoothSocket(bluetooth.L2CAP)
sock.connect((host, port))

song = open("/home/adrian_chlebosz/Downloads/song.wav", 'rb')
byte_array_song = bytearray(song.read())
song.close()

max_mtu_song = list()
for i in range(0, 64000):
    max_mtu_song.append(bytes(byte_array_song[(671 * i):(671 * (i +
                                                                1))]))

for i in range(0, len(max_mtu_song)):
    sock.send(max_mtu_song[i])
    sleep(0.5)
  • 1
    Something tells me that the device on the other end wants more than just a stream of bytes that it doesn't know what to do with. I might be wrong, but this feels like throwing colors at a blind person expecting them to understand what you're giving them. And depending on how you're set up the bluez manager in pulseaudio, it might not even work. Judging by how `find_service` is created, it looks like you need the `name="service name on server"` to connect to - which should tell the device what to expect when you send stuff. Again, these are all speculations and I might be miles off :) – Torxed Feb 05 '19 at 20:44
  • Bluetooth Audio only supports a handful of audio codecs. PCM is not one of them. – szatmary Feb 05 '19 at 22:25
  • @szatmary, could you tell me more about this? Which one of audio codecs Bluetooth Audio supports and maybe give a tip how to implement it? Thanks a lot! – Breader Man Feb 05 '19 at 22:37
  • Sorry, I can’t write a summary or Bluetooth audio codecs in a stackoverflow comment. But most of that information is available online already. – szatmary Feb 05 '19 at 22:40
  • I've made an additional research and found that something like SBC audio codec exists. I know how it works now but it's still not clear to me how to use it to send a song via bluetooth. I downloaded sbc encoder too but it requires "Sun/NeXT audio S16_BE format" which is ".au" audio format as Google said, unfortunately when I want to reformat sbc encoder tells me that I have wrong file format. – Breader Man Feb 06 '19 at 00:34
  • You need to use something like A2DP. Use the underlying system to handle this for you... it's not trivial. – Brad Feb 06 '19 at 23:18
  • I tried to use it but again everything went wrong, so I decided to try using D-Bus to connect my app with process which streams music to audio device. Maybe it will be better idea to solve problem. – Breader Man Feb 14 '19 at 21:49

0 Answers0