通过蓝牙从带有Ubuntu的PC到音频设备的音乐流

2024-04-16 08:47:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用ubuntu18.04将我的笔记本电脑中的音乐流到音频设备(lgcm2760)。我用Python编写了一个简短的脚本,我想在这里连接我的音频设备,然后播放音乐。我不确定,但认为建立连接是正确的,因为LG显示我的笔记本电脑的名称。不幸的是,当我开始“流媒体”时,只有沉默。问题可能是字节版本的歌曲,但我做了2天的研究,发现没有什么可以帮助我解决这个问题。你知道吗

我试着把这首歌转换成其他格式。你知道吗

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)

Tags: hostuuidsong音乐portmatchservicefind