標籤

2023年10月11日 星期三

同步口譯app的開發過程

 同步口譯app的開發過程

iPhone

即時語音辨識用內建的就很強

    private let speechRecognizer = SFSpeechRecognizer(locale: Locale(identifier: "zh-TW"))!

//    private let speechRecognizer = SFSpeechRecognizer(locale: Locale(identifier: "ja-JP"))!

//    private let speechRecognizer = SFSpeechRecognizer(locale: Locale(identifier: "en-US"))!

//    private let speechRecognizer = SFSpeechRecognizer(locale: Locale(identifier: "th-TH"))!

//    private let speechRecognizer = SFSpeechRecognizer(locale: Locale(identifier: "vi-VN"))!

//    private let speechRecognizer = SFSpeechRecognizer(locale: Locale(identifier: "ko-KR"))!


    private var recognitionRequest: SFSpeechAudioBufferRecognitionRequest?

    

    private var recognitionTask: SFSpeechRecognitionTask?

    

    private let audioEngine = AVAudioEngine()

        speechRecognizer.delegate = self

        

        // Asynchronously make the authorization request.

        SFSpeechRecognizer.requestAuthorization

  

可以參考xcode中的範例 SpokenWord


然後,翻譯的部分,我先嚐試用 google mlkit的翻譯,但翻譯品質很差,我打算改用google 雲端付費的api來試試,每月有50萬字的免費額度



google mlkit translate的作法

要先引用套件

pod 'GoogleMLKit/Translate''4.0.0'

然後使用的方法是

var mytr: Translator?

        let options = TranslatorOptions(sourceLanguage: .chinese, targetLanguage: .japanese)

        mytr = Translator.translator(options: options)

        let conditions = ModelDownloadConditions(

            allowsCellularAccess: false,

            allowsBackgroundDownloading: true

        )

        mytr?.downloadModelIfNeeded(with: conditions) { error in

            guard error == nil else { return }

            print("model ok")

            // Model downloaded successfully. Okay to start translating.

        }

                self.mytr?.translate(self.tv_talk.text) { translatedText, error in

                    guard error == nil, let translatedText = translatedText else { return }

                        self.tv_my.text=translatedText

                }

同樣也有範例參考 TranslateExample

下載位置 https://github.com/googlesamples/mlkit

2023年5月1日 星期一

使用OpenAI chatGPT技術, 根據公司公開重大訊息的內容做出解讀,主要是看這訊息對公司股東的影響,進而會不會影響到股價

 

使用OpenAI chatGPT技術, 根據公司公開重大訊息的內容做出解讀,主要是看這訊息對公司股東的影響,進而會不會影響到股價





天地資訊 : http://www.tendy.net/


程式碼

import requests
from bs4 import BeautifulSoup
import openai

url = "https://mops.twse.com.tw/mops/web/ajax_t05st01?firstin=1&TYPEK=all&step=2&seq_no=2&spoke_time=175712&spoke_date=20230501&co_id=2402&skey=2402202305012"

resp = requests.get(url)
html = resp.content
soup = BeautifulSoup(html,'html.parser')
text = soup.get_text()
text = text.replace('\n','')

openai.api_key = '自己的api key'
q = f"解讀以下內容對股東的影響 用少於100字來說明: \n\n{text}"
res = openai.ChatCompletion.create( model="gpt-3.5-turbo",messages=[{"role":"user","content":q}])
ans = res['choices'][0]['message']['content']
print(ans)



2023年4月1日 星期六

用python寫一支可以取得5秒加權指數歷史資料的程式

用python寫一支可以取得5秒加權指數歷史資料的程式 


import requests

import pandas as pd

import os


# 這個函數用來判斷要不要跳過某一行

def skip_rows(row):

    return row.startswith("說明:") or row.startswith("民國")


def download_taiex_csv(date):

    print(date+"下載轉換中")

     url = f'https://www.twse.com.tw/exchangeReport/MI_5MINS_INDEX?response=csv&date={date}&type=csv'

    response = requests.get(url)

    tmpfilename = f'tmp{date}.csv'

    with open(tmpfilename, 'w') as f:

        f.write(response.text)


     try:

        df = pd.read_csv(tmpfilename, skiprows=1)

    except ValueError:

        print(f'No data available for {date}')

    else:

        

        df = df[['時間', '發行量加權股價指數']]

        df.rename(columns={'發行量加權股價指數': '加權指數'}, inplace=True)

        df['時間'] = df['時間'].apply(lambda x: x.replace('=', '').replace('"', ''))

        df['時間'] = pd.to_datetime(df['時間'], errors='coerce')

        df['時間'] = df['時間'].dt.strftime('%H:%M:%S')

        df['加權指數'] = df['加權指數'].str.replace(',', '').astype(float)

        df = df.dropna(subset=['時間'])

        print(df.head())

        # 儲存為CSV檔案

        df.to_csv('taiex_%s.csv' % date, index=False)

    

    os.remove(tmpfilename)


# 主程式

start_date = '20230329'

end_date = '20230401'


for date in pd.date_range(start_date, end_date):

    download_taiex_csv(date.strftime('%Y%m%d'))


2023年3月26日 星期日

2023年3月16日 星期四

android上架後,下載的app icon為何變成內建小綠人,解決方法

 android上架後,下載的app icon為何變成內建小綠人,解決方法

不知道從哪個版本開始,android studio 把app icon 區分debug/release

據說是有助於開發人員識別


解決方法就是在res , 新建 image asset時

選好圖片的下一步,左上角會有選項顯示debug

這時去把這選項改為main就好了


2023年3月8日 星期三

Soup your photo 's privacy policy

Soup your photo 's  privacy policy

Soup uses cameras and photo albums, which are only for the user's own operation and use, and will not do any collection and sharing, nor upload to the Internet.


Soup has tandem mobile ads using Google's admob

iOS app 上架新增時,未出現套件識別碼的解決方法

 有可能是app沒有用到特別權限,所以xcode 未幫你註冊套件識別碼

這時只需要在xcode project -> target-> signing&Capabilities

隨意先新增一項,等xcode幫你註冊完成,再把這項刪掉就可以了