I've been using the following code to try and create a new playlist in iTunes and a song from the main library - its example code i've found but i keep getting the following error when it runs. I've had a look through the iTunes COM interface documentation and it seems that AddTrack is only available under IITLibraryPlaylist but all of the example code Ive found is as below. Can anyone help>
Error: AttributeError: win32com.ge_py.iTunes 1.13 Type Library.IITPlaylist instance at 0x34035192 object has no attribute 'AddTrack'
Python Code:
import win32com.client
itunes = win32com.client.gencache.EnsureDispatch ("iTunes.Application")
mainLibrary = itunes.LibraryPlaylist
tracks = mainLibrary.Tracks
playlist = itunes.CreatePlaylist("Sonic Jams")
song = tracks.ItemByName('Teen Age Riot')
playlist.AddTrack(song)
in C#
Cast to IITUserPlayList
IITUserPlaylist rclibrary = (IITUserPlaylist)itunes.LibrarySource.Playlists.ItemByName["name"];
rclibrary.AddTrack(item);
i managed to get it using this code if anyone else needs it.
playlist = win32com.client.CastTo(itunes.CreatePlaylist("New List"), 'IITLibraryPlaylist')
song = tracks.ItemByName('Silver Rocket')
playlist.AddTrack(song)
Related
I want to call a python function that uses numpy and pandas from my flutter app and get the output of this function.
I found a way to do that by using ffi package but I don't know how.
some says that I can do this by making a .dylib file from the python project then use this code to call it
final path = absolute('native/libadd.dylib');
final dylib = DynamicLibrary.open(path);
final add = dylib.lookupFunction('add');
but I am getting this error
: Error: Expected type 'NativeFunction<Function>' to be a valid and instantiated subtype of 'NativeType'.
lib/home_screen.dart:32
- 'NativeFunction' is from 'dart:ffi'.
- 'Function' is from 'dart:core'.
final add = dylib.lookupFunction('add');
so I think it's not available on Android
You should try using Flet for this. It is totally writted in Python language and still provide complete flutter functionality and code. Basic app code from it looks something like:
import flet as ft
def main(page: ft.Page):
page.title = "Flet counter example"
page.vertical_alignment = ft.MainAxisAlignment.CENTER
txt_number = ft.TextField(value="0", text_align=ft.TextAlign.RIGHT, width=100)
def minus_click(e):
txt_number.value = str(int(txt_number.value) - 1)
page.update()
def plus_click(e):
txt_number.value = str(int(txt_number.value) + 1)
page.update()
page.add(
ft.Row(
[
ft.IconButton(ft.icons.REMOVE, on_click=minus_click),
txt_number,
ft.IconButton(ft.icons.ADD, on_click=plus_click),
],
alignment=ft.MainAxisAlignment.CENTER,
)
)
ft.app(target=main)
It's just like a numpy or pandas library that you can import right into your project
As I said already sorry for the title. I have never worked with Azure API and have no idea what is wrong with the code, as I just copied from the documentation and put in my information.
Here is the code:
from azure.cognitiveservices.speech import AudioDataStream, SpeechConfig, SpeechSynthesizer, SpeechSynthesisOutputFormat
from azure.cognitiveservices.speech.audio import AudioOutputConfig
speech_config = SpeechConfig(subscription="ImagineHereAreNumbers", region="westeurope")
speech_config.speech_synthesis_language = "en-US"
speech_config.speech_synthesis_voice_name = "ChristopherNeural"
audio_config = AudioOutputConfig(filename=r'C:\Users\TheD4\OneDrive\Desktop\SpeechFolder\Azure.wav')
synthesizer = SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)
synthesizer.speak_text_async("A simple test to write to a file.")
Well as I run this I get no error and in fact, get in my desired folder a .wav file, but this file has 0 bytes and it looks corrupted.
Now here is why I have no idea of what's wrong because if I remove this
speech_config.speech_synthesis_language = "en-US"
speech_config.speech_synthesis_voice_name = "ChristopherNeural"
So it becomes this
from azure.cognitiveservices.speech import AudioDataStream, SpeechConfig, SpeechSynthesizer, SpeechSynthesisOutputFormat
from azure.cognitiveservices.speech.audio import AudioOutputConfig
speech_config = SpeechConfig(subscription="ImagineHereAreNumbers", region="westeurope")
audio_config = AudioOutputConfig(filename=r'C:\Users\TheD4\OneDrive\Desktop\SpeechFolder\Azure.wav')
synthesizer = SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)
synthesizer.speak_text_async("A simple test to write to a file.")
It now works all of the sudden, but with what I assume to be the basic/common voice.
So here is my question: how do I choose a voice that I want(btw is this one "en-US-JennyNeural" style="customerservice" or something among these lines)
Thank You in advance!
ChristopherNeural is not a valid voice name. The actual name of the voice is en-US-ChristopherNeural.
speech_config.speech_synthesis_voice_name = "en-US-ChristopherNeural"
This is well-documented on the Language support page of the Speech services documentation.
For other, more fine-grained control over voice characteristics, you'll require the use of SSML as outlined in text-to-speech-basics.py.
I am trying to export a tableau view as an image/csv (doesn't matter) using Python. I googled and found that REST API would help here, so I created a Personal Access Token and wrote the following command to connect: -
import tableauserverclient as TSC
from tableau_api_lib import TableauServerConnection
from tableau_api_lib.utils.querying import get_views_dataframe, get_view_data_dataframe
server_url = 'https://tableau.mariadb.com'
site = ''
mytoken_name = 'Marine'
mytoken_secret = '$32mcyTOkmjSFqKBeVKEZYpMUexseV197l2MuvRlwHghMacCOa'
server = TSC.Server(server_url, use_server_version=True)
tableau_auth = TSC.PersonalAccessTokenAuth(token_name=mytoken_name, personal_access_token=mytoken_secret, site_id=site)
with server.auth.sign_in_with_personal_access_token(tableau_auth):
print('[Logged in successfully to {}]'.format(server_url))
It entered successfully and gave the message: -
[Logged in successfully to https://tableau.mariadb.com]
However, Iam at a loss now on how to access the tableau workbooks using Python. I searched here:-
https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_workbooks_and_views.htm
but was unable to write these commands like GET or others in python.
Can anyone help?
I'm assuming you don't know the view_id of the view you're looking for
Adding this after the print in the with block will query all the views available on your site;
all_views, pagination_item = server.views.get()
print([view.name for view in all_views])
Then find the view you're looking for in the printed output and note the view_id for use like this;
view_item = server.view.get_by_id('d79634e1-6063-4ec9-95ff-50acbf609ff5')
From there, you can get the image like this;
server.views.populate_image(view_item)
with open('./view_image.png', 'wb') as f:
f.write(view_item.image)
The tableauserverclient-python docs should help you out a ton as well
https://tableau.github.io/server-client-python/docs/api-ref#views
I am trying to use the IMDbpy library in my django projects,but it raises an Attribute Error.
I tried all the solutions available on the internet,but none seem to work,could you please help me with this?
The Error:
moviesDB = imdb.IMDb()
AttributeError: module 'imdb' has no attribute 'IMDb'
The code:
import imdb
moviesDB = imdb.IMDb()
movies= moviesDB.search_movie('whatever_movie')
id = movies[0].getID()
movie = moviesDB.get_movie(id)
print(movie)
title=movie['title']
rating = movie['rating']
cover=movie['cover url']
print(title,rating,cover)
I have been scratching my head the entire day,due to this error,I'm kinda new to this,so please help!
I tried reinstalling the imdbpy library,pip3 installed it,renamed it but nothing seems to be working.
The code is working in external files,but in the views.py in django,it just doesnt seem to work
please help!
Try from imdb import IMDb then use IMDb() to initialize
I am trying to build a calendar image using the package calendar-view. Below is the code from calendar-view:
from calendar_view.calendar import Calendar
from calendar_view.core import data
from calendar_view.core.event import Event
config = data.CalendarConfig(
lang='en',
title='Sprint 23',
dates='2019-09-23 - 2019-09-27',
show_year=True,
mode='working_hours',
legend=False,
)
events = [
Event('Planning', day='2019-09-23', start='11:00', end='13:00'),
Event('Demo', day='2019-09-27', start='15:00', end='16:00'),
Event('Retrospective', day='2019-09-27', start='17:00', end='18:00'),
]
data.validate_config(config)
data.validate_events(events, config)
calendar = Calendar.build(config)
calendar.add_events(events)
calendar.save("sprint_23.png")
This code works perfectly fine, however, I have been trying to build a similar calendar dynamically. As in, number events may increase or decrease. Is there a way to make this code behave more dynamic?
Here is some info on how I have tried making this dynamic:
I wrote the event details (shown below) in to a txt file.
[
Event('Planning', day='2019-09-23', start='11:00', end='13:00'),
Event('Demo', day='2019-09-27', start='15:00', end='16:00'),
Event('Retrospective', day='2019-09-27', start='17:00', end='18:00'),
]
Then read the text file in to the field 'event' (as shown below)
event = open("instruction.txt", "r")
But the code fails because it considers everything that has been read from file as a 'str'. Please see error below:
AttributeError: 'str' object has no attribute 'get_start_date'
You can use this code:
with open('instruction.txt', 'r') as file:
file_content = file.read()
events = eval(file_content)
eval() is the function that executes the string and returns the Python object.